System.CalloutException: Имате чакаща неизвършена работа. Моля, ангажирайте или върнете назад

Моят код CreateTimeLine е

public static void createTimeLine(List<sObject> objList,Map<String,String> contentMap){
Map<Id,User> userMap = new Map<Id,User>([Select id,Name From User where Authorize__c = true]);
Map<Id,GlassUserApiSettings__c> userSettingsMap = new Map<Id,GlassUserApiSettings__c>();

for(Id user_id : userMap.keySet()){
GlassUserApiSettings__c userSettings = GlassUserApiSettings__c.getValues(user_id);
if(userSettings == null)
{ User u =userMap.get(user_id);
u.Authorize__c = false;
update u;
}
else userSettingsMap.put(user_id,userSettings);

}
for(sObject obj : objList)
for(Id userId: userSettingsMap.keySet() ){
String type = '';
if(contentMap.get('Object').equals('FeedItem'))
type='Post';
if(contentMap.get('Object').equals('FeedComment'))
type= 'Comment';
GlassUserApiSettings__c userSettings = userSettingsMap.get(userId);
if(((String)obj.get(contentMap.get('Content'))).contains('@'+userMap.get(userId).Name)){
Datetime tokenExpiredTime = userSettings.LastModifiedDate;
tokenExpiredTime.addSeconds(Integer.valueOf(userSettings.ExpireDuration__c));
String body='{"html":"<article><section><div class="text-auto-size">'+type+':'+
'<p class="yellow">"'+obj.getSObject('CreatedBy')+'&nbsp;'+obj.getSObject('CreatedBy')+'</p><p>'+obj.get(contentMap.get('Content'))+'</p>'+
'</div></section> </article>"}';
System.debug('Body is '+body);
/* if(tokenExpiredTime >= System.now()){
GMirror.TokenResponse res = GMirrorUtil.refreshToken(userSettings.RefreshToken__c);
userSettings.RefreshToken__c = res.refresh_token;
userSettings.AccessToken__c = res.access_token;
userSettings.ExpireDuration__c = Integer.valueOf(res.expires_in) ;
update userSettings;
}*/
String timelineRes = doApiCall(body,'POST','https://www.googleapis.com/mirror/v1/timeline',userSettings.AccessToken__c);
GMirror.TimelineResponse createdTimeCard = (GMirror.TimelineResponse) JSON.deserialize(timelineRes,GMirror.TimelineResponse.class);
if(createdTimeCard.id != null)
System.debug('created timeline card :'+createdTimeCard);
else { try{
throw new GMirror.TimelineException(null,timelineRes);
}
catch(Gmirror.TimelineException e){
System.debug(e.getMessage());
}
}
}
}
}

и My Batch apex код е

public class BatchPublishTimeLine implements Database.Batchable<sObject>{
sObjectIterable iterable;
Map<Id,User> userMap;
Map<String,String> contentmap;

public BatchPublishTimeLine(List<sObject> objectList,Map<String,String> contentmap){
iterable = new sObjectIterable(objectList);
this.userMap = new Map<Id,User>([Select Id,Name From User WHERE Authorize__c = true]);
this.contentmap = contentmap;
}
public Iterable<sObject> start(Database.BatchableContext BC){
return iterable;
}
public void execute(Database.BatchableContext BC, List<sObject> scope){
GMirrorUtil.createTimeLine(scope, contentMap);
}

public void finish(Database.BatchableContext BC){
System.debug('Job Has been Finished');
}
}

public static String doAPICall(String postBody, String method, String endPoint, String accessToken){

HttpRequest req = new HttpRequest();
Http http = new Http();
HttpResponse res;

req.setEndpoint(endPoint);
req.setMethod(method);
req.setHeader('Content-Type','application/json');

if(method == 'POST' || method == 'PUT')
req.setBody(postBody);
req.setHeader('Authorization','Bearer ' + accessToken);
res = http.send(req);
String result = res.getBody();
System.debug('status code is '+res.getStatus());
System.debug('result is'+res.getBody());
return result;
}

Извиквам batch apex от тригер след функция за вмъкване, получавам тази грешка от ред

String timelineRes = doApiCall(body,'POST','https://www.googleapis.com/mirror/v1/timeline',userSettings.AccessToken__c);

Не използвам никакъв DML оператор след функцията doApiCall, както можете да видите. Но защо се сблъсквам с тази грешка?? Моля, насочете как да го разрешите.


person Ritesh Mehandiratta    schedule 25.09.2013    source източник
comment
Но всъщност човек с вашата репутация трябва първо да потърси в Google този въпрос...   -  person Andrii Muzychuk    schedule 27.09.2013


Отговори (1)


Правите актуализация, преди да направите допълнително описание - update u; и update userSettings;. Трябва да правите тези актуализации след извикване.

person Andrii Muzychuk    schedule 26.09.2013
comment
всъщност тестовият случай, който тествам, не покрива тези DML операции, все още получава грешка, затова се извинявам, че не представям по правилния начин. - person Ritesh Mehandiratta; 27.09.2013
comment
извиквам batch apex от тригер след функцията sert. Получавам тази грешка от ред ‹= вашите думи. Казвам, че не е позволено да правите надпис (във вашата партида) след операция за вмъкване. - person Andrii Muzychuk; 28.09.2013