ControllerToUpdateDWREAffiliation.getAccessToken(affIds) is the future method containing the affiliation list of 17 records. Thanks much.
List<String> affIds = new List<String>();
List<npe5__Affiliation__c> affiliationList = new List<npe5__Affiliation__c>();
User demandwareAppUser = [select Id from User where Name = 'Demandware'];
if(Trigger.isUpdate){
system.debug('--------------------'+demandwareAppUser.Id);
for(npe5__Affiliation__c affiliation: Trigger.new){
if(affiliation.LastModifiedById != demandwareAppUser.Id){
system.debug('Affiliation Details'+'--'+'--'+affiliation.LastModifiedById);
affiliationList.add(affiliation);
}
}
}
system.debug('*************Affiliation Size :'+affiliationList.size());
Boolean affiliateHasChanged = false;
for(Integer count = 0; count < affiliationList.size() ; count++){
if(trigger.new[count].affiliationBatchFlag__c == 'updated'){
extraAffs++;
AccountHelper ah = new AccountHelper(trigger.new[count].Id);
affIds.add(JSON.serialize(ah));
system.debug('----------**********************--------'+trigger.new[count].Id+'--'+trigger.new[count].npe5__Status__c+'--'+trigger.new[count].Mozo_User_Level__c+'--'+trigger.new[count].affiliationBatchFlag__c);
if(math.mod(extraAffs,10) == 0)
{
ControllerToUpdateDWREAffiliation.getAccessToken(affIds);
affIds.clear();
}//batch ids
}
if(trigger.old[count].npe5__Status__c != trigger.new[count].npe5__Status__c ||
trigger.old[count].Mozo_User_Level__c != trigger.new[count].Mozo_User_Level__c){
extraAffs++;
affiliateHasChanged = true;
system.debug('----------**********************--------'+trigger.new[count].Id+'--'+trigger.new[count].npe5__Status__c+'--'+trigger.new[count].Mozo_User_Level__c);
//if(!system.isbatch()){
AccountHelper ah = new AccountHelper(trigger.new[count].Id);
affIds.add(JSON.serialize(ah));
// TW: The following IF condition gets the even nnumber count of Ids on INSERT. This is neededdue to the @future call outs to Google.
if(math.mod(extraAffs,10) == 0)
{
ControllerToUpdateDWREAffiliation.getAccessToken(affIds);
affIds.clear();
}//batch ids
//}
}
}
if(math.mod(extraAffs ,10) != 0){
ControllerToUpdateDWREAffiliation.getAccessToken(affIds);
affIds.clear();
}//other than batch
We found the solution to solve our Batch class issue. we have analyzed the code step by step using debug log and found it is caused because of DML and Callout statements of execution. For updating affiliations to Demandware we have to use one more Batch class to avoid calling from Batch because updating flag from finish method didn't work. We have scheduled two classes with 5 minutes of gap and it worked well. I can go though the code i have changed in the Batch Class. Thanks.