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
Chinna SfdcChinna Sfdc 

Need help for FIELD_CUSTOM_VALIDATION_EXCEPTION

Hi Team,

When we are running the below batch apex  we are facing the erros like "FIELD_CUSTOM_VALIDATION_EXCEPTION, When the Customer Connect Request Status is Pending or Approved, the Account Name and Address cannot be edited ".Actually there is a validation rules are firing.How we can avoid the validation rules using my code?Please find my below code which we are trying and help us to avoiding the errors.

Apex Class:

global class OpportunityDays implements Database.Batchable<Sobject>{
    global OpportunityCWDays(){
    }    
    global Database.QueryLocator start(Database.BatchableContext BC){  
     
        String query = 'Select id, StageName, Software_Product_Count__c, CW_in_Last_30_Days_Formula__c, CW_in_Last_30_Days_Workflow__c, CW_in_Last_730_Days_Formula__c, CW_in_Last_730_Days_Workflow__c from Opportunity Where  Software_Product_Count__c > 0 AND StageName = \'S8- Closed Won\'
        ;
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC,List<Opportunity> lstOpp){ 
        for(Opportunity objOpp : lstOpp){
            if(objOpp.CW_in_Last_30_Days_Formula__c && !objOpp.CW_in_Last_30_Days_Workflow__c) {
                objOpp.CW_in_Last_30_Days_Workflow__c = TRUE;
            }   
            else if(!objOpp.CW_in_Last_30_Days_Formula__c && objOpp.CW_in_Last_30_Days_Formula__c ) {
                objOpp.CW_in_Last_30_Days_Workflow__c = False;
            }
            
            if(objOpp.CW_in_Last_730_Days_Formula__c  && !objOpp.CW_in_Last_730_Days_Workflow__c) {
                objOpp.CW_in_Last_730_Days_Workflow__c = True;
            }   
            else if (!objOpp.CW_in_Last_730_Days_Formula__c && !objOpp.CW_in_Last_730_Days_Workflow__c){
                objOpp.CW_in_Last_730_Days_Workflow__c = False;
            }                                    
        }
        update lstOpp;    
    }    
    
    global void finish(Database.BatchableContext BC){        
    }  
}

Thanks
 
Dilip_VDilip_V
Hi Chinna,

Any triggers on opportunity.Check once.

Thanks.