Hi Sandy, please check below example
If you find your Solution then mark this as the best answer.global class batchClassToUpdateTrailheadData implements Database.Batchable<sObject>,Database.Stateful {
global integer total = 0;
global integer success = 0;
global integer failure = 0;
global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator('select ModuleName__c,(select name from Moduless__r where pickList__c = \'Completed\') from TrailHeadData__c ');
}
global void execute(Database.BatchableContext bc,list<TrailHeadData__c> thdList){
for(TrailHeadData__c thdObj : thdList){
if(thdObj.Moduless__r.size()>0){
thdObj.ModuleName__c = thdObj.Moduless__r[0].name;
}
}
Database.SaveResult[] res = Database.update(thdList,false);
for(integer i = 0;i<res.size();i++){
Database.SaveResult resObj = res.get(i);
if(resObj.isSuccess()){
success += 1;
}
else{
failure += 1;
}
total += 1;
}
}
global void finish(Database.BatchableContext bc){
system.debug('Total Processed records ==> '+total+' Total success records ==> '+success+' Total faliure records ==> '+failure);
}
}
Thank you!
Regards,
Suraj Tripathi
1 resposta