Update Opportunity Description Based on Stage

In Salesforce, the Opportunity object serves as the core for revenue tracking, forecasting, and deal progress. But when teams across sales, finance, and operations need quick context about where a deal stands, relying solely on the Stage field isn’t always enough—especially when scanning records or integrating with external tools.

That’s where this simple yet impactful automation comes in.

In this blog, we walk through a before update Apex trigger on the Opportunity object that dynamically updates the Description field based on the current Stage. When an Opportunity moves to Closed Won, Closed Lost, or stays open in any other stage, the Description automatically reflects the status in a clean, readable format like:

  • “Opportunity is Closed Won”

  • “Opportunity is Closed Lost”

  • “Opportunity is Open”

This provides an at-a-glance summary that improves communication, enhances reporting, and ensures consistent messaging across the org.

🧠 Why This Trigger Matters


While StageName tells you a lot, the Description field is often used to convey quick notes or human-readable summaries—whether for users, integrations, or downstream processes. By auto-filling it based on deal status, you:

  • Reduce manual entry for reps

  • Ensure consistency in how deal status is described

  • Make it easier to scan Opportunity records

  • Enhance integrations or document generation that rely on Description

  • Provide better visibility across teams—especially in list views, emails, or exports

It’s a small touch that makes a big impact on clarity and user experience.

🔍 What This Blog Covers


  • How to use a before update Apex trigger to automate field values

  • How to detect StageName changes using Trigger.oldMap

  • How to auto-populate the Description field with consistent messaging

  • When to use conditional logic to handle multiple outcomes

  • Why this approach improves reporting, clarity, and team efficiency

  • How to write clean and modular Apex using a handler class

This trigger doesn’t just save keystrokes—it supports a consistent CRM experience across roles, regions, and record types.

🎯 Real-World Use Cases for This Trigger


  • Sales teams who want instant clarity on deal status

  • Executives reviewing Opportunities in dashboards or list views

  • Customer success or onboarding teams checking deal context post-closure

  • Revenue teams generating reports where Description is shown in exports

  • Admins aiming to eliminate inconsistencies in manual notes

This automation is especially useful in high-volume orgs where every second saved in record management adds up to better productivity.

👨‍💻 Developer & Admin Tips


The trigger checks if:

  • The StageName field has changed (using Trigger.oldMap)

  • Or the oldMap is null (for extra safeguard or optional use in inserts)

Based on the current StageName, the Description is set to one of the following:

  • “Opportunity is Closed Won”

  • “Opportunity is Closed Lost”

  • “Opportunity is Open”

All of this is handled in the before update context, meaning no additional DML is required—Salesforce saves the updated Description automatically with the record.

The logic is handled in a separate trigger handler class for clean code, future maintainability, and easier testing. It’s fully bulk-safe and built for production readiness.

Want to refine this further? You can localize the messaging, add emojis for visual flair, or use Custom Metadata for easy configuration.

🎥 Hands-On Demo – YouTube Playlist Included


For a visual walkthrough of this use case, check out the Salesforce Makes Sense YouTube playlist linked in this post. You’ll see:

  • How the trigger works

  • How to test it in your dev org

  • Where to place logic in the handler class

  • How to apply this same model to other objects and fields

This playlist is built to help you master Apex with real-world business logic—not just syntax, but true CRM problem-solving.

Solution:

trigger OpportunityTrigger on Opportunity (before update) {
                if(Trigger.isUpdate){ if(Trigger.isBefore){
                     OpportunityTriggerHandler.updateDesc(Trigger.New,
                     Trigger.oldMap);
             }
      }
}
     public class OpportunityTriggerHandler { public static void
                     updateDesc(List oppList,Map oldMap){
                                    for(Opportunity opp:oppList){
                                          if((oldMap==null)||(opp.StageName!=oldMap.get(opp.Id).Stage
                                                  Name)){ if(opp.StageName==’Closed Won’){                                                                                                          opp.Description=’Opportunity is
                                                  Closed won’;
                                     }else if(opp.StageName==’Closed Lost’){ opp.Description=’Opportunity is closed lost’;
                                     }else{ opp.Description=’Opportunity is open’;
                              }
                     }
              }
      }
}

Want to Apply As Content Writer?

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart

Let's get you started!

Interested in writing Salesforce Content?

Fill in this form and we will get in touch with you :)