function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VamsiVamsi 

heap size limit error on callout to external endpoint

Hi,

We are making a callout to external endpoint from Salesforce to get the attachments. when attachment size is more than 6 MB its throwing me Heap size limit error and we are running this callout from future method, where we are having this limit as 12 MB.

Please advise .... on any workarounds to overcome this ..
 
@future(callout=true)
    public static void SendAttachmentsToCase(Map<string,string> Initialres,ID CaseID,ID UserID,string UserName,string Password,string ticketNumber,string jobtime)
    {

                // Performs another callout to get appropriate attachment 
               List<attachment> FinalAttachmentList = new List<attachment>();
               for(string sg : Initialres.Keyset()) // Map of attachment Names and endpoint
               {
                Http h2 = new Http();
                HttpRequest req2 = new HttpRequest();
                Blob headerValue = Blob.valueOf(UserName+':'+Password);
                String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
                req2.setHeader('Authorization', authorizationHeader);
                req2.setHeader('Content-Type','application/json');
                req2.setEndpoint(Initialres.get(sg));
                req2.setMethod('GET');
                req2.setTimeout(60000);
                try
                {
                system.debug('heap size before req'+' '+ Limits.getHeapSize());
                HttpResponse res2 = h2.send(req2);
                system.debug('resposne'+ ' '+res2.getBody());
                                system.debug('heap size after req'+' '+ Limits.getHeapSize());

                blob image = res2.getBodyAsBlob(); 
                Attachment a = new Attachment (ParentId = CaseID,
                                           Body = image,
                                           OwnerId = UserID,
                                           CreatedById = UserID,
                                           Name = sg);
               FinalAttachmentList.add(a);
                }catch (Exception e)
                {
                    system.debug('exception message at 2nd callout level'+ ' '+ e.getMessage());
                 }
              }

              insert FinalAttachmentList;
    }

 
VamsiVamsi
Hi Saket,

Thanks I know we have this pilot program but I was looking out for other recommendations 
<Saket><Saket>
Hi Vamsi

If you don't mind can you please share from which third party you are integrating your system?
VamsiVamsi
I'm getting Attachments from Zendesk