salesforce - Too many callouts: 11 in DataBase.Batchable -
i have code segment in database.batchable
if(pagetoken!=null) deleteevents(accesstoken , pagetoken,c.calendarid__c); }
and delete event function code
public static void deleteevents(string accesstoken,string pagetoken,string calendarid){ while(pagetoken != null) { string re = gcalendarutil.doapicall(null,'get','https://www.googleapis.com/calendar/v3/calendars/'+calendarid+'/events?pagetoken='+pagetoken,accesstoken); system.debug('next page response is'+ re); re = re.replaceall('"end":','"end1":'); re = re.replaceall('"datetime":','"datetime1":'); json2apex1 aa = json2apex1.parse(re); list<json2apex1.items> ii = aa.items ; system.debug('size of ii'+ii.size()); pagetoken = aa.nextpagetoken ; list<string> event_id =new list<string>(); if(ii!= null){ for(json2apex1.items i: ii){ event_id.add(i.id); } } for(string ml: event_id) system.debug('hello worlds'+ml); for(string s:event_id) { gcalendarutil.doapicall(null,'delete','https://www.googleapis.com/calendar/v3/calendars/'+calendarid+'/events/'+s,accesstoken); } } }
because there 180 event thats why getting error deleting them have alternative create custom object , text field (id of event)in , create 1 more database.batchable class deleting them , pass batch of 9 or other method able more 100 callouts in database.batchable interface??
10 max. , doesn't seem google's calendar api supports mass delete.
you seek chunking batch job (the size of list of records passed each execute()
call). illustration this:
global database.querylocator start(database.batchablecontext bc){ homecoming database.getquerylocator([select id event]); // loops through events , not accounts } global void execute(database.batchablecontext bc, list<account> scope){ // deletes here } database.executebatch(new mybatchclass(), 10); // create sure work on 10 events (or less) @ time
another alternative read daisy-chaining of batches. in execute you'd deleting 10, in finish()
method check 1 time again if there's still more work , can fire batch again.
p.s. don't utilize hardcoded "10". utilize limits.getcallouts()
, limits.getlimitcallouts()
automatically update if salesforce ever increases limit.
in trigger illustration set 10 @future methods, each fresh limit of 10 callouts... still batch sounds improve idea.
salesforce apex-code
No comments:
Post a Comment