I am trying to upload a file in salesforce and send it to Sharepoint for storage using synchronous call. However, when i upload file more than 5MB i am encountering an issue like below :' {FAILURE=Exceeded max size limit of 6000000 with request size 6004736}

The debug logs says the following : enter image description here



I am aware that the heap size limit is 6MB. But earlier when i was uploading 24.5MB it was uploading and storing in Sharepoint without any issue. Recently in last 2 weeks i am seeing this error of Max size for even 6MB files.

After searching in Google, i found that making variables as transient or using @future solves issue, but i can use neither in my code. Posting the code for your reference :

 public static HttpRequest prepareRequestWithBlob(String endPointURL, Attachment file, String method){

    String fileByteSize = String.valueOf(file.BodyLength-1)+'/'+String.valueOf(file.BodyLength);
    system.debug('fileByteSize --------'+fileByteSize);
    HttpRequest request = new HttpRequest();
    //if (Limits.getHeapSize() < Limits.getLimitHeapSize()){
    request.setHeader('Content-Length', String.valueOf(file.BodyLength));
    request.setHeader('Content-Range', 'bytes 0-'+fileByteSize);
    system.debug('request in SPU---------'+request);          
    string fileEncoded = EncodingUtil.base64Encode(file.Body);

    Blob bodyBlob = EncodingUtil.base64Decode(fileEncoded);

  //  }else{
  //      system.debug('Throw custom exception');
  //  }

    return request;

The line string fileEncoded = EncodingUtil.base64Encode(file.Body); in the above code fails everytime i upload file > 5MB.

Your help is greatly appreciated on how to handle this type of error.

  • When you say -- "But earlier when i was uploading 24.5MB it was uploading and storing in Sharepoint without any issue" -- were you using exactly the same code to do so? – Jayant Das Jul 16 '18 at 13:10
  • Yes Jayant. Its the same code. We havent changed the code at all. – user47646 Jul 17 '18 at 5:33

The actual limit is going to be closer to 4,500,000 bytes before encoding. Note that it has never been possible to send more than 12,000,000 bytes of data in a single transaction, and even then, only for asynchronous code. If for some reason you were able to send more than 6MB/12MB, this was a bug that has since been fixed.

It should never have been possible to send more than 12MB payloads under any circumstances. The net result is that you won't be able to do this in Apex Code. Instead, you'll want to use the AJAX Proxy to send the data directly from the user's browser to its final destination. Unlike Apex Code, it has theoretically unlimited payload sizes (I've tested this with files exceeding 250MB).

Governor limits are not meant to be broken, and there is no workaround. I don't know the specifics of the SharePoint API, but you might be able to break up your request into multiple parts if you still want to use Apex Code, but it still would not be a single-transaction, synchronous callout.

|improve this answer|||||
  • 1
    The AJAX Proxy link seems to be broken (it redirects to the Visualforce landing page, for me at least). – David Reed Jul 16 '18 at 13:15
  • @DavidReed Thanks. I had just copied it from my bookmark, didn't realize it was dead. – sfdcfox Jul 16 '18 at 13:19

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.