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
enossirenossir 

Apex class field update clashing with a validation rule.

// before update, process only trigger.new opps and trigger.old maps 
    public static void befUpdate(List<Opportunity> newOpps, Map<Id,Opportunity> oldMapOpps){    
        oppFldUpdates(newOpps,oldMapOpps);
        OppFiscalQuarterDates(newOpps);
        validateOppUpdate(newIGTOpps,oldMapOpps);      
       
         for (Opportunity opp : newOpps){
            if(opp.Signature_Received__c == true) opp.StageName = 'Closed Won';
            if(opp.StageName == 'Closed Won')opp.CloseDate = date.today();     
             }
        
    }

So when the opp stagename is closed won then the close date is switched to today, no i didnt use a workflow because theres too much business logic on other handlers that work off the opportunity install and close dates.

but the problem is, is when the install date > close date before this class updates. Ie

install date = 1/13/2019
close date = 1/4/2019  apex class field update ---> 1/2/2019

but what fires off is this
 
AND(Install_Date__c <= CloseDate, 
ISPICKVAL( Term_Conversion__c ,"")
)


Because it's reading the previous value of the closedate, now these are on old opps obviously....but a lot of them are like this. I'd really hate to have to hard code another validation rule into my class handler.