function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdcbynitesfdcbynite 

Testing Roll-up Summary Update Trigger

Obj A has a m-d to child Obj B. On Obj A there is a roll-up summary field bSUM which sums up all field b's in all Obj B children. When the r.u.s filed bSUM updates (recalculates) a trigger is fired on Obj A. Now, this all works when I do actual record creation. But in my unit tests, the SOQL and asserts are getting called before the bSUM has updated, which means no trigger was fired yet and therefore the asserts fail. Anybody know what I can do to delay the assertions until the trigger has fired? My apologies if this post is not formatted properly. For some odd reason I no longer get the rich text editor.
Navatar_DbSupNavatar_DbSup

Hi,


I don’t think you have to bother about the child record since you have written the trigger on Parent Object. So you have to make the data in such a way that it fits the condition which you have used inside the trigger. Try the below code as reference:
@isTest
private class testTriggerinsert_Contact_Activity
{
public static testMethod void unitTestinsert_Contact_Activity4Task()
{
ParentObject__c p=new ParentObject__c(name='test',othere mendatory fields);
insert p;
update p;
}
}
Even if you have any issue the please post your trigger code.

 

 

sfdcbynitesfdcbynite
It's a bit more complicated. Really Parent Obj A, has 2 children B and C. When a new B record is inserted, it changes roll up field bSUM on A. Then in the update trigger on A, a new C record is created. I am currently testing C trigger functionality.

So what I think I'll do is fake the C record created from the A update trigger in the C trigger test class. Then I'll have to deal with the A update when I revise the A trigger test code.