You need to sign in to do that
Don't have an account?
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 Criteria: Evaluate the rule when a record is created, and any time it’s edited to subsequently meet criteria
Rule Criteria : Task: 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: Trigger.new)
{
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];
if(aa.Account_Status__c=='Accepted')
{
mydate=newtask.ActivityDate+5;
Task tskupd=new Task(ownerId=newtask.ownerId,whatId=newtask.whatId,Subject='Send11 Letter',Priority='Normal',Status='Not Started',ActivityDate=mydate);
tasksupd.add(tskupd);
}
Database.insert(tasksupd);
}
}
}
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
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm
See the points 3,6,9,10,11
Another imp blog
http://blog.softwareallies.com/2010/08/triggers-workflows-and-salesforces.html
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
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