Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
- //Create a list to hold Tasks
- List<Task> taskList = new List<Task>();
- //Create Opportunity Trigger for Inserts and Updates by capturing the Opportunity ID's
- for(Opportunity opp : Trigger.new) {
- if(Trigger.isInsert) {
- if(Opp.StageName == 'Closed Won') {
- taskList.add(new Task(Subject = 'Follow Up Test Task', WhatId = opp.Id));
- }
- }
- if(Trigger.isUpdate) {
- if(Opp.StageName == 'Closed Won' && Opp.StageName != Trigger.oldMap.get(opp.Id).StageName) {
- taskList.add(new Task(Subject = 'Follow Up Test Task', WhatId = opp.Id));
- }
- }
- }
- //Check to see if any Opportunites created tasks
- if(taskList.size()>0) {
- //Insert the new tasks
- insert taskList;
- }
- }
Add Comment
Please, Sign In to add comment