function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alfredo Puente VasconcelosAlfredo Puente Vasconcelos 

System.CalloutException: Exceeded max size limit of 12000000

I'm having problems when I call an external web service from Salesforce Apex. When I try to call the web service, I get a System.CalloutException. I believe that the cause of the problem is that the response is too long that Salesforce can't handle it. Is there any problem in my code? How can I consume web service with long json responses with Apex?

Thank you for your attention
 
future(Callout=true)
public static void webServiceCall(){
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint(' here_is_my_url ');
    request.setMethod('GET');
    request.setHeader('Content-Type','application/json');
    request.setTimeout(120000);
    HttpResponse response = http.send(request);
}

 
Deepali KulshresthaDeepali Kulshrestha
Hi Alfredo,

This error message is due to a maximum size of call out response which is 6MB. This error is typical because of the following issue 
a) (Maximum size of callout request or response) 
b) maximum allowed heap size (6MB sync / 12MB async). 

You may also try to set up the debug logs and check for the Apex heap size error to confirm. 
I would like to mention that the limit for both max sizes of call out (request and response ) and heap size is 6MB. 
Best practices for running within the Apex heap size 

I suggest you visit this link, it will help you:

https://help.salesforce.com/articleView?id=000004186&language=en_US%C2%A0&type=1

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.