Last active
May 1, 2024 12:03
-
-
Save ganmahmud/540ed0110df56489e10cde31c82de5f4 to your computer and use it in GitHub Desktop.
Create an Apex trigger for Opportunity that adds a task to any opportunity set to 'Closed Won'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger ClosedOpportunityTrigger on Opportunity(after insert, after update) { | |
List<Task> oppList = new List<Task>(); | |
for (Opportunity a : [SELECT Id,StageName,(SELECT WhatId,Subject FROM Tasks) FROM Opportunity | |
WHERE Id IN :Trigger.New AND StageName LIKE '%Closed Won%']) { | |
oppList.add(new Task( WhatId=a.Id, Subject='Follow Up Test Task')); | |
} | |
if (oppList.size() > 0) { | |
insert oppList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
trigger ClosedOpportunityTrigger on Opportunity(after insert, after update)
{
List TaskList = new List();
}