0

I have created the Rest Resource to send the data with Attachment to outside the salesforce (GET Method - REST API).

@HttpGet 
global static List<wrapper1> getCVH() { 
wrapper1.rows row; 
for(CVH__c cvh: database.query(queryString)){ 
    List <Attachment> attachmentList = [SELECT Id, Name, Body, ParentId FROM 
    Attachment WHERE ParentId = :cvh.Id limit 1]; 
    if (attachmentList.size() > 0){ 
      Attachment att = attachmentList[0]; row.AttachmentName = att.Name; 
    row.AttachmentBody = EncodingUtil.base64Encode(att.Body); //This line is causing error 
} 
} 
lstConv.add(cvhWrap); 
return lstConv; 
} 

The problem is I am getting the error

System.LimitException: JSON string exceeds heap size limit

Now, I now that for synchronous call the heap size limit is 6 MB and I can increase it to 12 MB if I do asynchronous call(Batch or Future).

But I didn't have an idea how can I achieve that.

Please let me know how can I achieve this?

Here is a code snippet:

@HttpGet global static List<wrapper1> getCVH() { 
    wrapper1.rows row; 
    for(CVH__c cvh: database.query(queryString)){ 
        List <Attachment> attachmentList = [SELECT Id, Name, Body, ParentId FROM Attachment WHERE ParentId = :cvh.Id limit 1]; 
        if (attachmentList.size() > 0){ 
            Attachment att = attachmentList[0]; 
            row.AttachmentName = att.Name; 
            row.AttachmentBody = EncodingUtil.base64Encode(att.Body); //This line is causing error 
        } 
    } 

    lstConv.add(cvhWrap); 
    return lstConv; 
} 

Thanks

  • Can you provide at least the method signature and preferably the line that is causing the issue? – Phil Hawthorn Jan 15 '18 at 9:21
  • @HttpGet global static List<wrapper1> getCVH() { wrapper1.rows row; for(CVH__c cvh: database.query(queryString)){ List <Attachment> attachmentList = [SELECT Id, Name, Body, ParentId FROM Attachment WHERE ParentId = :cvh.Id limit 1]; if (attachmentList.size() > 0){ Attachment att = attachmentList[0]; row.AttachmentName = att.Name; row.AttachmentBody = EncodingUtil.base64Encode(att.Body); //This line is causing error } } lstConv.add(cvhWrap); return lstConv; } – Nirav Shah Jan 15 '18 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.