We are using this APEX REST API class to take pdf from our third party client. Functionality works fine however when file size is more than 6 MB, we get an error:
Apex heap size too large: 8014366
I understand we are hitting heap here however, is there a way that we can bypass this error? It seems weird to me that Salesforce doesn't allow sending more than 6 MB document on APEX REST API. Is there a possible workaround to this issue?
@RestResource(urlMapping='/v1/SampleV1/*')
global with sharing class SampleV1 {
@HttpPost
global static CaseWrapper doPost(String Title, String JSON, String VersionData, string Description, string PathOnClient, String ClientId ) {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
CaseWrapper response = new CaseWrapper ();
List <ContentVersion> CaseListInsert = New List <ContentVersion> ();
ContentVersion CV = new ContentVersion ();
CV.Title = Title ;
// CV.JSON__c= Jsonsample;
CV.VersionData = EncodingUtil.base64Decode(VersionData);
CV.Description = 'Sample';
CV.PathOnClient = 'Sample Doc.pdf';
CV.ClientId__c = ClientId;
Insert CV;
response.status = 'Success';
response.StatusCode = 201;
response.message = 'Sample PDF was created successfully.';
return response;
}
global class CaseWrapper {
public List<Attachment> AttachmentList;
public String status;
public String message;
public integer StatusCode;
public CaseWrapper (){
AttachmentList = new List<Attachment>();
}
}
}