//Create an Apex trigger with the following information:
//Object: Opportunity
//Name: ClosedOpportunityTrigger
//Events: After Insert and After Update
//Conditions: Stage is Closed Won
//Operation: Create a task with the following information:
//Subject: Follow Up Test Task
//WhatId: Opportunity ID (associates the task with the opportunity)
//Bulkification: The trigger should be bulkified so that it can insert or update up to 200 records at a time.
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
List tasks = new List();
for(Opportunity opp : Trigger.new){
// Check if the StageName has changed to 'Closed Won'
if(opp.StageName == 'Closed Won' && (Trigger.isInsert || opp.StageName != Trigger.oldMap.get(opp.Id).StageName)){
Task t = new Task();
t.Subject = 'Follow Up Test Task';
t.WhatId = opp.Id;
tasks.add(t);
}
}
insert tasks;
}
Instead of only checking if the `StageName` is `Closed Won`, which means it creates tasks for all opportunities that are inserted or updated
with that stage, even if they were already `Closed Won` before the update, you'd only want to create tasks when an opportunity is closed, not every time a `Closed Won` opportunity is updated.
Remember, while Salesforce allows you to process up to 200 records at a time, you should always write your code to handle bulk operations using collections like lists, sets, and maps to avoid hitting governor limits.