i have written a future method here is source code
@future(callout=true) public static void futureDownloadAttachment(Set<ID> documentsID){ List<SpringCM_Attachment__c> logs = [Select Id,Object_ID__c,SpringCM_Document_Id__c,Attachment_Id__c From SpringCM_Attachment__c Where Id IN :documentsId]; System.debug('logs are'+logs); for(Integer i=0;i<logs.size(); i++) if(logs[i].Attachment_Id__c == null) { logs[i] = downloadAttachment(logs[i]); update logs[i] ; } } public static SpringCM_Attachment__c downloadAttachment(SpringCM_Attachment__c log){ System.debug('coming here'); Http h = new Http(); HttpRequest req = new HttpRequest(); req.setEndPoint(SpringCM_Uploader_Settings__c.getOrgDefaults().Heroku_service__c+'/downloadDocument?documentId='+log.SpringCM_Document_Id__c); req.setMethod('GET'); HttpResponse res = h.send(req); System.debug('response body is'+res.getBody()); AttachmentInfo attachInfo; Attachment a; if(res.getStatusCode() ==200) { attachInfo = (AttachmentInfo) System.JSON.deserialize(res.getBody(),AttachmentInfo.class); log.Status__c = AttachInfo.Status; log.Upload_details__c = AttachInfo.detail; if(attachInfo.DocumentDownloadResult != null) { a = new Attachment(); a.Body = Blob.valueOf(attachInfo.DocumentDownloadResult); a.Name= attachInfo.documentName; a.ParentId = log.Object_Id__c; furtherProcess = false; insert a; } } if(res.getStatusCode() != 200) { log.Status__c = 'Error - Heroku'; log.Upload_details__c = res.getBody().substring(0,2490); } log.Object_type__c = String.valueOf(((ID)log.Object_ID__c).getSObjectType()); if(a != null) log.Attachment_ID__c = a.Id; return log; } i am getting error You have uncommitted work pending. Please commit or rollback before calling out.how to resolve this issue.Please help