How can i add a condition to fire my trigger when my opp stagename is closed?

trigger TriggerOnPrevious on Opportunity (before update) {
    for(Opportunity opp : Trigger.New){
        String oldStageName = Trigger.oldMap.get(opp.Id).StageName;
        if(opp.StageName != oldStageName){
             opp.Previous_stage__c = oldStageName;
  • Please read How to Ask, as it will help you write questions in a way that will help the community help you.
    – Robs
    Nov 15, 2018 at 15:35

1 Answer 1


Update your if condition with below code

if( opp.StageName.equalsIgnoreCase('Closed Won') && opp.StageName != oldStageName)

  • apex is case inSenSitIvE, so equalIgnorecase and == will give the same result. Nov 15, 2018 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.