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
aaryansriaaryansri 

Based on multi picklist value remain filed values should change in batch apex

Hi,

My bacth class execute method based on mulit select picklist values other filed values should update. I wrote below condition it's getting error. Please help me out.

if(pr.NO_OF_EMPLOYESS__C<100 && (includes(pr.Products__c , 'Antivirus') && includes(pr.Products__c , 'Laptop') && includes(pr.Products__c , 'PC'))){
}

Error:Compile Error: Method does not exist or incorrect signature: includes(String, String) 
ManojjenaManojjena
Hi Aryansri ,
Try with below code it will help !
 
if(pr.NO_OF_EMPLOYESS__C<100 && pr.Products__c.contains('Antivirus') && pr.Products__c.contains('Laptop') && pr.Products__c.contains('PC')){
}
Let me know if it helps !

Thanks 
Manoj

 
aaryansriaaryansri
Hi Manoj,  

  Thanks for your reply, The above code not given any error but it is not working.
below is the batch code




global class partnerbatch  implements Database.Batchable<sobject>{
public Integer failureRecords{get;set;}
String failureRec;
Integer cnt=0;
public partnerbatch(){
failureRecords=0;
}
global Database.Querylocator start(Database.BatchableContext bc){
String query='select ID,NAME,NO_OF_EMPLOYESS__C,Approval_Status__c,D_B_ACCOUNT__C,COMPANY_DESCRIPTION__C,IS_US_BASED_COMPANY__C,ANNUAL_REVENUE__C,TAX_ID__C,REGISTRATION_NO__C,COUNTRY__C,STATE__C,PRODUCTS__C from Partner_Registration__c';
return Database.getQuerylocator(query);
}
global void execute(Database.BatchableContext bc,list<Partner_Registration__c> scope){
for(Partner_Registration__c pr : scope){
system.debug('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
if((pr.NO_OF_EMPLOYESS__C<100) && (pr.Products__c.contains('Antivirus')) && (pr.Products__c.contains('Laptop')) && (pr.Products__c.contains('PC'))){
//if(pr.NO_OF_EMPLOYESS__C<100){
system.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@');
pr.NO_OF_EMPLOYESS__C=pr.NO_OF_EMPLOYESS__C+100;
system.debug('##############################'+pr.NO_OF_EMPLOYESS__C);
}
}
list<Database.SaveResult> res= Database.update(scope,false);
for (Database.SaveResult rec : res){
 cnt++; 
     if(!rec.Success){
            failureRecords++;
           String name= scope[cnt].name;          
          failureRec= failureRec+',';
          
          system.debug('****************'+name+'&&&'+failureRec);
}
}
}
global void finish(Database.Batchablecontext bc){
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    String[] toAddresses = new String[] {'11.ashok.k@gmail.com'};
    mail.setToAddresses(toAddresses);
    mail.setReplyTo('noreply@salesforce.com');
    mail.setSenderDisplayName('Batch Job Summary');
    mail.setSubject('Batch job completed');
    mail.setPlainTextBody('Batach completed successfully'+failureRec);
    Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
}
}


  It's not updating the "No of Employees" field and even not getting faild records.