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
Ker Vin.ax1237Ker Vin.ax1237 

Assignment rules and trigger execution sequence

From the sfdc documentation, the execution is as follows.

  1. Executes all before triggers.
  2. Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules. The only system validation that Salesforce doesn't run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.
  3. Saves the record to the database, but doesn't commit yet.
  4. Executes all after triggers.
  5. Executes assignment rules.
  6. Executes auto-response rules.
  7. Executes workflow rules.
  8. If there are workflow field updates, updates the record again.
  9. If the record was updated with workflow field updates, fires before and after triggers one more time (and only one more time), in addition to standard validations. Custom validation rules are not run again.


I have written a "After insert" trigger that will create and attach a task that has customized comment information (based on the lead that triggers it). I want this task to be created AFTER the assignment rules have been executed. Otherwise, the task will be assigned to one person and the lead to another.

To do this, I wrote a workflow rule that will update a flag to true and modified the trigger to only execute the task creation if the flag is set to true. My understanding is that the on the first run, the trigger won't work because the flag is false, assignment rules will then change the Lead Owner, Workflow rules will update the flag and then lastly the trigger will execute (properly this time)

Unfortunately, the trigger doesn't seem to execute the second time. Is my understanding wrong? When I reviewed the debug log, the 2nd execution of the trigger that I was expecting doesn't occur.

kiranmutturukiranmutturu

hope it will work with update events ...y because with the workflow the record is updating in the backend.. so may be u need to specify the update event..like before update or after update....try it like that once...

Navatar_DbSupNavatar_DbSup

Hi,

 

I don’t think there is anything wrong in your approach. May be you have to check your workflow rule that it’s working as per your requirement or not.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Ker Vin.ax1237Ker Vin.ax1237

Well, you were right that if I trigger it as an before/after update it will work, but I was hoping that the after insert will work. The reason is if I use a before/after update, that flag will need to be catered for by other triggers as there are some other validation rules on the Lead.

 

Anyone have an idea where I can still use after insert?

Ker Vin.ax1237Ker Vin.ax1237

In fact, for some reason I'm still tracing, the trigger appears to be executing twice, writing TWO tasks. If I were to use after insert (without the flag) it only runs once.

kiranmutturukiranmutturu

if that is the case dont use checkbox type to differentiate y because The before and after triggers fire one more time only if something needs to be updated. If the fields have already been set to a value, the triggers are not fired again...so its better to have a text field if it is null then set the value as 'true' in that...as per the above statement triggers will never fire for second time if a value is already set .according to ur scenario it is set with false..i think thats y u are facing this issue.. lets try the other way too..