Governor limits include
Maximum size of callout request or response (HTTP request or Web services call) - 3 MB
Does this include downloading files via HTTP from external servers? Will those files also be restricted to 3 megabytes?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
If you are using an
HTTPRequest from within Apex to retrieve or send a document to an external server, then yes, you are making a "callout", so the total payload of the HTTPRequest you are creating must be less than 3MB in size. See the HttpRequest docs, in particular the
setBodyAsDocument methods, for further proof of this. The corresponding
get methods don't reiterate the 3MB limit, but I believe that the limit is the same regardless of whether you are sending or retrieving data.
Furthermore, this callout counts towards the total Heap Size limit for a single Apex transaction, which is 6MB (or 12MB if you're in Batch Apex, which can make callouts as well if properly annotated). So, for instance, if you need to post 3 large documents, say 1.9 MB a piece that you're generating from within Apex to an external service, you could do 3 separate callouts within a single Apex transaction, and you would presumably be at only around 5.7 MB for your total heap size, and since no single callout generated a request body of greater than 3 MB, you should be fine.
If you have control over the remote endpoint that you are downloading / posting files to, you might want to take a look at leveraging the
setCompressed methods of the
HttpRequest class - these allow you to apply gzip compression to the file you are either retrieving or posting, with the intention of the data later being extracted / expanded, once you are outside of the Apex transaction. This could help you avoid some of the heap size limits, if you are able to later extract the files from the zipped format.