Skip to main content
All,

 

I woul appreciate any help with my requirement below .  I am kind of new in coding and I would appreciate any assitance

REQUIREMENT

 

When Opportunity record is connected to one or more Matter__c  record, Sum all currency values in the Total_Fees__c currency field and add Sum total value in the Engagement_Total_Fees__c field in the related Opportunity record

 

OBJECTS

Opportunity (parent object)

Matter__c  (Child object) custom object.

 

 

OPPORTUNITY FIELD

Engagement_Total_Fees__c - currency (16,2) custom field

 

MATTER__C field

Total_Fees__c - currency (16,2) custom field

Deal__c  - Lookup(Opportunity) custom field

 

WHAT I HAD DONE

 

Below is a trigger I created based on website https://github.com/abhinavguptas/Salesforce-Lookup-Rollup-Summaries .

 

I am requesting if you can review my code because I received the error below

 

“Error: Compile Error: Invalid type: LREngine.Context at line 26 column 33”

 The data on line 26 is “LREngine.Context ctx = new LREngine.Context(Opportunity.SobjectType, // parent object

Trigger Below

/* Updated version on 17 June 16

*/

trigger OppRollupOnEngagement on Matter__c (after insert, after update, 

                                        after delete, after undelete) 

// modified objects whose parent records should be updated

     {Matter__c[] objects = null;

if (Trigger.isDelete) {

         objects = Trigger.old;

 /*

      Handle any filtering required, specially on Trigger.isUpdate event. If the rolled up fields

      are not changed, then please make sure you skip the rollup operation.

      We are not adding that for sake of similicity of this illustration.

 */ 

        objects = Trigger.new;

     }

/*

      First step is to create a context for LREngine, by specifying parent and child objects and

      lookup relationship field name

*/

     LREngine.Context ctx = new LREngine.Context(Opportunity.SobjectType, // parent object

                                            Matter__c.SobjectType,  // child object

                                            Schema.SObjectType.Matter__c.fields.Deal__c // relationship field name

                                            ); 

/*

      Next, one can add multiple rollup fields on the above relationship. 

      Here specify 

       1. The field to aggregate in child object

       2. The field to which aggregated value will be saved in master/parent object

       3. The aggregate operation to be done i.e. SUM, AVG, COUNT, MIN/MAX

*/

ctx.add(

            new LREngine.RollupSummaryField(

                                            Schema.SObjectType.Opportunity.fields.Engagement_Total_Fees__c,

                                            Schema.SObjectType.Matter__c.fields.Total_Fees__c,

                                            LREngine.RollupOperation.Sum 

                                         )); 

/* 

      Calling rollup method returns in memory master objects with aggregated values in them. 

      Please note these master records are not persisted back, so that client gets a chance 

      to post process them after rollup

*/ 

Sobject[] masters = LREngine.rollUp(ctx, objects);    

     // Persiste the changes in master

     update masters;

}

I would appreciate the help . 

 
5 answers
  1. Jun 17, 2016, 7:35 PM
    Did u try using process builder to do rollup between parent and child objects?
0/9000