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
Mariappan PerumalMariappan Perumal 

Doubt: Order of Execution in salesforce

Hi all ,


I have written the trigger on task  , whenever i closed the task i will generated another task after 5 days from the due date ,


But it fire the trigger exactly twice in my salesforce org,


I found that some other workflow make my trigger to fire again , I have also attached the crietria and field update of that workflow below for the reference ,

Evaluation CriteriaEvaluate the rule when a record is created, and any time it’s edited to subsequently meet criteria

Rule CriteriaTask: StatusEQUALSCompleted


Field Update: some date/time field in the task .




trigger TaskforEnrolledStatus on Task (before update) {
Date mydate;
List<Task> tasksupd = new List<Task>();
for(Task tsk:
Task oldtask=Trigger.oldMap.get(tsk.Id);
Task newtask=Trigger.newMap.get(tsk.Id);

if(newtask.Status=='Completed'&& oldtask.Status!=newtask.Status ){
Account aa=[Select id,Account_Status__c from Account where id=:newtask.whatId];

Task tskupd=new Task(ownerId=newtask.ownerId,whatId=newtask.whatId,Subject='Send11 Letter',Priority='Normal',Status='Not Started',ActivityDate=mydate);





My Question here is like Order of execution on salesforce is trigger and then workflow ,

1.Trigger will fire and create the task when we close one task, and then workflow will fire and update the date/time field and 

How come the trigger will fire again ?.


Thanks in advance



See the points 3,6,9,10,11


Another imp blog


If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.


From the order of Execution ,right from the docs :
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.

Currently ,this is calling trigger recursively .For this you need to set the Boolean Flag(some kind of flag) . You will find plenty of solution for restricting Recursive calls in Apex Triggers