In a high-performing sales organization, the close of a deal is only the beginning of the next set of responsibilities. Whether it’s revenue splitting, onboarding, or internal handovers, post-sales workflows must be clear and immediate. That’s where Salesforce automation steps in.
In this blog, we walk through a powerful and practical Apex trigger that automatically creates a Task for the Opportunity Owner whenever the Opportunity Stage is updated to “Closed Won.” This ensures that follow-up actions are never missed, team collaboration is maintained, and deal handoffs are streamlined without relying on manual to-do lists.
The trigger executes during the after update context, identifying Opportunities that have moved into the “Closed Won” stage and assigning a related Task to the appropriate user.
🧠 Why This Trigger Matters
In many organizations, the sales-to-service transition is a critical moment. After a deal is closed:
-
Revenue may need to be split between teams
-
Client onboarding needs to begin
-
Internal finance or support teams require handoff tasks
-
Account managers must prepare for renewals or upsell conversations
Manually assigning these tasks is prone to delays and oversight. Automating this process ensures:
-
Consistent follow-up after every deal is won
-
Time saved for sales managers and admins
-
Structured workflows across departments
-
No dropped handoffs during customer transitions
This small automation makes a big difference in maintaining operational excellence and team accountability.
🔍 What This Blog Covers
-
How to use an after update Apex trigger to monitor stage changes
-
How to generate Task records automatically based on field values
-
Why using clean, handler-based Apex structure improves maintainability
-
How to dynamically assign Task ownership to the Opportunity owner
-
Where this automation fits within broader CRM workflows
This is a classic example of automating sales ops—keeping things clean, organized, and friction-free post-closure.
🎯 Real-World Use Cases for This Trigger
-
Sales teams needing to initiate internal revenue split reviews
-
Customer onboarding teams triggered automatically once a deal is won
-
Finance teams requiring documentation or payment steps post-closure
-
Account managers being prepped to begin client engagement
-
Service teams handed tasks for provisioning, setup, or delivery
Regardless of your business model, this automation helps you move fast after a win—without skipping a beat.
👨💻 Developer & Admin Tips
Here’s how the logic works:
-
The trigger fires after the Opportunity is updated
-
It checks whether the StageName has been set to “Closed Won”
-
For qualifying Opportunities, it creates a new Task record
-
The Task is assigned to the Opportunity Owner
-
It includes a high-priority flag and a custom subject and description
-
All generated Tasks are inserted in bulk after the loop
This setup ensures:
-
Bulk-safe operation (handles multiple Opportunities at once)
-
Customizable logic (can extend for different stages or multiple Task types)
-
Easy maintenance through a centralized handler method
-
Reusability if additional automations are added later
Want to take this further?
-
Use custom labels for the Task description and subject
-
Add conditions for specific Opportunity record types or products
-
Link the Task to a Campaign or Contact if needed
-
Trigger email alerts or chatter posts alongside Task creation
You can also pair this logic with reporting to track:
-
Time-to-follow-up metrics
-
Task completion rates
-
Deal handoff SLAs
🎥 Step-by-Step Demo – YouTube Playlist
Need help visualizing the setup? Check out the Salesforce Makes Sense YouTube playlist, where this exact trigger is broken down in a developer-friendly walkthrough. The demo includes:
-
How to build and test the Apex handler
-
Tips for writing clean, scalable trigger code
-
Real-time results in the Salesforce UI
-
Troubleshooting common errors and enhancements
This video series is perfect for admins, developers, and anyone learning Salesforce automation through real-world examples.
Solution:
public class OpportunityTriggerHandler {
public static void handleActivitiesAfterInsert () {}
public static void handleActivitiesAfterUpdate (List<Opportunity> newRecords) {
List<Task> taskListToInsert = new List<Task> ();
for (Opportunity opp: newRecords) {
if (opp.StageName == ‘Closed Won’) {
//create a related record Task record
Task taskRecord = new Task();
taskRecord.Priority = ‘High’;
taskRecord.OwnerId = opp.OwnerId;
taskRecord.Description = ‘Please split the revenue amongst the team members’;
taskRecord.Status = ‘Not Started’;
taskRecord.Subject = ‘Split Revenue’;
taskRecord.WhatId = opp.Id;
taskListToInsert.add(taskRecord);
}
}
if (!taskListToInsert.isEmpty())
insert taskListToInsert;
}
}