0

My class that utilizes this LREngine utility class aggregates numbers up a hierarchy. The problem I'm facing is that when an account is deleted the number fields are not subtracting values from the total numbers displayed on parent accounts in the hierarchy

My Class:

public class LAM_LRE_Rollup{

     /*
      First step is to create a context for LREngine, by specifying parent and child objects and
      lookup 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
         */

          */ 
         Sobject[] masters = LREngine.rollUp(ctx, lstAccts);    


         // Push the changes in master

         update masters;
      }
}

My Trigger:

   /*List<Account> acc = new List<Account>([SELECT Id, ParentId FROM Account WHERE id IN:Trigger.newMap.keySet()]);
       for (Account a : trigger.new) {
        if (Trigger.isUpdate && a.ParentId != Trigger.oldMap.get(a.Id).ParentId ){
            LAM_LRE_Rollup.rollupData(trigger.new);

    }
*/


}
2
  • 1
    N.B. I believe LRE is included inside of DLRS which is the preferred solution for rollup summaries cross lookup relationships
    – cropredy
    Commented Mar 14, 2019 at 16:58
  • Are you posting under multiple accounts? If so, please use the Contact link at the bottom of the page to have Stack Exchange merge them.
    – David Reed
    Commented Mar 21, 2019 at 11:31

1 Answer 1

1

You have to call your logic on delete and undeletetrigger.

trigger LAM_DataRollup on Account (after insert, after update, after delete, after undelete) {

    if(trigger.isInsert || trigger.isUpdate || trigger.isUndelete)
    {
        LAM_LRE_Rollup.rollupData(trigger.new);
        system.debug('db');

    }
    if(Trigger.isDelete){
         LAM_LRE_Rollup.rollupData(trigger.old);
            system.debug('db');
    }

}

Src : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm

5
  • Thanks for the response. I've added this exact logic previously and it did not resolve the issue
    – user64312
    Commented Mar 14, 2019 at 15:18
  • Whats the code of LREngine , does it do SOQL inside?4 Commented Mar 14, 2019 at 15:19
  • the code for the LREngine is too large to post here but it does do SOQL
    – user64312
    Commented Mar 14, 2019 at 15:23
  • Without looking at code, I dont think anyone can help. But if the code is called in trigger in this manner, it should work. I have a similar implementation and it works, Commented Mar 14, 2019 at 15:25
  • Ive updated the question with the LREnging
    – user64312
    Commented Mar 14, 2019 at 15:58

You must log in to answer this question.