+ Start a Discussion
Tirthankar DastidarTirthankar Dastidar 

How to send large attachment from Salesforce to third party through apex batch

Hello, I have a requirement to send Attachment file data to a third party system. Currently I am quering each attachment in a separate batch and then convert the blob data to base64 string to form a specific XML for the third party API to accept. Then issueing a apexcallout to send the attachment data to that system.
string requestBody = '<Job><InputType>'+attachment.ContentType.substringAfter('/')+'</InputType><InputURL></InputURL><InputBlob type="binary">'+EncodingUtil.base64Encode(attachment.Body)+'</InputBlob></Job>
request.setBody(requestBody);

This is working fine although the problem is with large attachments. When in an average, an attachment is of size around 7MB, the base64 string is hitting the System.heaplimitexception of 12MB and the callout fails. Salesforce supports to attach a file upto 25MB size, so i have to support that file size. But I am severely limited by the heaplimit exception. I tried the
request.setBodyAsBlob()

o send the blob data directly to external system but that again it has only 3MB of limit. Could you please help me to show any solution to get around it?
Thanks in advance.
cooldamselcooldamsel
Hi Thirthankar,

I am trying to send an attachment from salesforce to an external Web service. I am facing 415 error as "Media type not supported." Could you please suggest how you have achieved this functionality.

Thanks in advance.
Kumar SauravKumar Saurav
Hi Thirthankar,

Yes there is a limit from salesforce side for sending large size attachement.You can overcome this limit by using 3rd party storage server for storing the file content as well as sending them over the email with large size attachment.
Cloud Drop is One such App that is some what following the same logic in order to store any number and size of files that can be associated with any salesforce object with Rackspace server.It also allow user to send very large size file as email attachment to particular contact/lead record.
Please check the following link for more information:
https://appexchange.salesforce.com/listingDetail?listingId=a0N30000003IzEDEA0