You need to sign in to do that
Don't have an account?
Rabbani sayyed 8
I need to Create an Apex trigger for Opportunity that adds a task to any opportunity set to 'Closed Won' . Can anyone share me the code for this with best practises.
I need to Create an Apex trigger for Opportunity that adds a task to any opportunity set to 'Closed Won' . Can anyone share me the code for this with best practises.
You can achieve this easily through Workflow (Task).
However, With Trigger You can use this code:
Warm Regards,
Sourav.
You can use this code:
trigger testTrigger on Opportunity(before update, after insert){
list<task> listToInsert = new list<task>();
for(opportunity opp : trigger.new){
if(opp.stageName == 'Closed Won'){
task taskObject = new task();
taskObject.whatId = opp.Id;
taskObject.subject = 'test';
listToInsert.add(taskObject);
}
}
if(!listToInsert.isEmpty()){
insert listToInsert;
}
}
Hope this helps!
Thanks
You must go with Workflow Only. But also if you want trigger then pls refer below code: