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
ShamilShamil 

Order of execution: triggers and formula fields

Contact has 2 fields:

1. a custom lookup field to User: User__c

2. a custom cross-object formula field that pulls a custom field from User: User_Field__c

 

According to Apex documentation the step below executes after the 'after trigger':

"If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the

roll-up summary field in the parent record. Parent record goes through save procedure."

 

Questions:

1. Is it guaranteed that I will always see the value of the User_Field__c field in Contact's after insert trigger? In my tests I can see the value coming through - does this fact contradict with the statement in documentation?

2. What does cross-object workflow mean in this specific context?

Shashikant SharmaShashikant Sharma

Questions:

1. Is it guaranteed that I will always see the value of the User_Field__c field in Contact's after insert trigger? In my tests I can see the value coming through - does this fact contradict with the statement in documentation?

 

Ans : It might be coming but vaules get commited to databse only after the Parent record goes through save procedure."

 

2. What does cross-object workflow mean in this specific context?

 

Ans : cross-object workflow means where workflow uses any entry criteria which include another object as well.

ShamilShamil

Shashikant, what does "It might be coming but vaules get commited to databse only after the Parent record goes through save procedure" mean? User record is the parent, what save procedure does it go through when there are no changes to it?

Also, why is it that "it might be coming ..." - what is the explanation for this non-deterministic behavior if it is true?

 

Shashikant SharmaShashikant Sharma

Let me try to answer why it is coming, lets have a scenario where you have written a trigger on a object after insert and you validate something in that and if it does not satisfy you do not allow it to get inserted. That does not mean that you will not see posible values to be saved in before insert trigger. You will see them and can add any logic on these value even though that logic will be reverted back if after insert fails..

ShamilShamil

Thanks, Shashikant, what you said is partially correct (roll-up summary fields wouldn't show up), but it doesn't answer my question, which is:

 

Is it guaranteed that I will always see the value of the User_Field__c field in Contact's after insert trigger? In my tests I can see the value coming through - does this fact contradict with the statement in documentation?

 

I'm looking for an answer that is based on some insight platform knowledge, not just quotes from the public documentation and guesses.