2

Hi All I have a requirement were external webservice should handle more than 3MB of data. I am trying to send document/files to external system using callout. Is there any alternative way such as sharing a url for document/files? Can I use any other API apart from SOAP to achieve this? If use the callout in Batch apex/Future class can this be achieved?

7

I've faced the same issue time ago. In my case the files where stored as attachments.

I must warn you that sending the complete file body is a bad idea. You will not only face the size limit, also the time limit. Avoid that idea

My workaround to overcame that limit was to send the URL to get the attachment body by REST. Then the external service get the file content.

Sample:

curl https://na1.salesforce.com/services/data/v20.0/sobjects/Attachment/001D000000INjVe/body -H "Authorization: Bearer token"

The rest of the file metadata (name, etc) is send with the url.

More information about this here

0

You could break the file up into separate pieces and send the pieces. I believe the callout limit is 10 callouts per execution, so you could send about 30MB of data.

You could do something like this:

Blob blob = yourFile;
String file = blob.toString();
List<String> chunks = magicallySplitStringInto3mbChunks(file);
if(chunks.size() < 10){
    Integer chunkNum = 0;
    for(String chunk: chunks){
        Map<Integer, String> postData = new Map<Integer,String>();
        postData.put(chunkNum, chunk);
        String jsons = JSON.serialize(postData);
        postChunk(jsons);
        chunkNum ++;
   }
}

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.