global class BatchHandlerForUpdateSequenceinCAPAGT implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'select id,Record_Type_Name__c,Sequence__c,Adhoc_Sequence__c,Sequence_Position__c from General_Task__c where CAPA__c!=NULL';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<General_Task__c> genTasks) {
for(General_Task__c gtask:genTasks){
if(gtask.Record_Type_Name__c != 'AdhocTask'){
if(String.isBlank(gtask.Sequence__c)){
gtask.Sequence__c=String.valueof(integer.valueof(gtask.Sequence_Position__c));
}
}else {
if(String.isBlank(gtask.Adhoc_Sequence__c)){
gtask.Adhoc_Sequence__c=String.valueof(integer.valueof(gtask.Sequence_Position__c));
}
}
}
try {
update genTasks;
} catch(Exception e) {
System.debug(e);
}
}
global void finish(Database.BatchableContext BC) {
// execute any post-processing operations
}
}
Z2xvYmFsIGNsYXNzIEJhdGNoSGFuZGxlckZvclVwZGF0ZVNlcXVlbmNlaW5DQVBBR1QgaW1wbGVtZW50cyBEYXRhYmFzZS5CYXRjaGFibGU8c09iamVjdD4geyAKICAgIGdsb2JhbCBEYXRhYmFzZS5RdWVyeUxvY2F0b3Igc3RhcnQoRGF0YWJhc2UuQmF0Y2hhYmxlQ29udGV4dCBCQykgeyAKICAgICAgICBTdHJpbmcgcXVlcnkgPSAnc2VsZWN0IGlkLFJlY29yZF9UeXBlX05hbWVfX2MsU2VxdWVuY2VfX2MsQWRob2NfU2VxdWVuY2VfX2MsU2VxdWVuY2VfUG9zaXRpb25fX2MgZnJvbSBHZW5lcmFsX1Rhc2tfX2Mgd2hlcmUgQ0FQQV9fYyE9TlVMTCc7IAogICAgICAgIHJldHVybiBEYXRhYmFzZS5nZXRRdWVyeUxvY2F0b3IocXVlcnkpOyAKICAgIH0gCiAgICBnbG9iYWwgdm9pZCBleGVjdXRlKERhdGFiYXNlLkJhdGNoYWJsZUNvbnRleHQgQkMsIExpc3Q8R2VuZXJhbF9UYXNrX19jPiBnZW5UYX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