function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jonathan WallaceJonathan Wallace 

Reset Boolean Flag on Apex Trigger?

I have a trigger that fires when an opportunity is closed, I'm using the IsClosed boolean. However i've noticed that opportunities that are set to "Awarded"  don't trigger when they are changed to closed. I'm thinking that this is because the flag has already been triggered with the "IsWon" boolean. Is there anyway to reset the flag ? 
here is my trigger.
trigger ClosedOpportunityTrigger on Opportunity (before insert, before update) {
    for(Opportunity opp : Trigger.New) {
        Id closedBy; // defaults to null
        
        Date closedOn;                                                                                                                                        
        
        if (opp.IsClosed) {
            // set closed by to last modified user
            closedBy = opp.LastModifiedById;
            closedOn = opp.LastModifiedDate.date();
            
            // reset closed by to original user if record already closed
            // handles when user changes another field but leaves Opp closed
            if (Trigger.isUpdate) {
                Opportunity old = Trigger.OldMap.get(opp.Id);
                if (old.IsClosed == opp.IsClosed) {
                    closedBy = old.Closed_By__c;
                    closedOn = old.Closed_date__c;
                }
            }   
        } 
        // setting these values here handle re-opening Opp
        opp.Closed_By__c = closedBy;
        opp.Closed_date__c = closedOn;
    }
}

 
Kevin CrossKevin Cross
Jonathan, is "Awarded" meant to be one of your "Closed" options?  If so, try edited the picklist option and set type to "Closed/Won" and forecast category to "Closed."  In addition, you always can use the Stage Names in the IF condition but the way you have it you can add additional closed statuses without editing your trigger.