我的DataBase.Batchable中有一个代码段
if(pageToken!=null)
deleteEvents(accessToken , pageToken,c.CalendarId__c);
}和delete事件函数代码是
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);
}
}
}因为大约有180个事件,这就是为什么我得到这个错误的原因,但是为了删除它们,我可以选择在其中创建一个自定义对象和一个文本字段(事件id),然后再创建一个用于删除它们的Database.Batchable类,并将其作为9个批次或任何其他方法传递,这样我就可以在Database.Batchable接口中使用100多个标注。
发布于 2013-02-18 19:41:20
10是最大值。而且谷歌的日历API似乎不支持批量删除。
您可以尝试将批处理作业分块(传递给每个execute()调用的记录列表的大小)。例如,如下所示:
global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator([SELECT Id FROM Event]); // anything that loops through Events and not say Accounts
}
global void execute(Database.BatchableContext BC, List<Account> scope){
// your deletes here
}
Database.executeBatch(new MyBatchClass(), 10); // this will make sure to work on 10 events (or less) at a time另一种选择是阅读有关批处理菊花链的知识。在execute中,您将删除最多10个,在finish()方法中,您将再次检查是否还有更多工作要做,并且您可以再次触发批处理。
附言:不要使用硬编码的"10“。使用Limits.getCallouts()和Limits.getLimitCallouts(),以便在Salesforce增加限制时自动更新。
例如,在触发器中,你可以设置10个@future方法,每个方法都有10个标注的新限制……不过,batch听起来是个更好的主意。
https://stackoverflow.com/questions/14934590
复制相似问题