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
Tom SimmonsTom Simmons 

Help with Callout to external system

All, below is my code. While trying to make callout to an external API, I`m getting an error “System.CalloutException: Exceeded max size limit of 6000000” synchronously. I believe this is happening since payload that is being received is very large. I was wondering if there is a way to work across these limits. I tried using @future too however its giving me an error too "System.LimitException: Apex heap size too large: 12649268". Can someone please suggest a better way to get data in Salesforce?
 
HttpRequest obj = new HttpRequest();
    HttpResponse res = new HttpResponse();
    Http http = new Http();
    String reqBody = '{ "user": "test_user", "passwd": "2gbwefgnaiognawgona12" }';
    obj.setMethod('POST');
    obj.setHeader('Content-Type','application/json');
    obj.setEndPoint('https://test.samplepoint.com/api/UserSrvs.svc/Login');
    obj.setBody(reqBody);
    obj.getheader('Auth-Token');
    res = http.send(obj);
                            system.debug('Oauth Response: '+res.getbody());
                           system.debug('Header Auth-Token Response: '+res.getHeader('Auth-Token'));

            authtoken objAuthenticationInfo = (authtoken)JSON.deserialize(res.getbody(), authtoken.class);
            System.debug('objAuthenticationInfo: '+objAuthenticationInfo);


      Http h1 = new Http();
    HttpRequest req1 = new HttpRequest();
    String reqBody2 = '{ "Accountype" : "workforce"}';
    req1.setHeader('Auth-Token', res.getHeader('Auth-Token'));
    req1.setHeader('Content-Type','application/json');
    req1.setMethod('POST');
     req1.setBody(reqBody2);

    req1.setEndpoint('https://test.samplepoint.com/api/accservices.svc/accountfeed');//URL will be your Salesforce REST API end point where you will do POST,PUT,DELETE orGET
    system.debug('======req1========'+req1);
    HttpResponse res1 = h1.send(req1);
    system.debug('==========res1============'+res1.getBody());

 
Subramani_SFDCSubramani_SFDC
The maximum heapsize of future method is 12MB
Normal heapsize is 6MB only.

you should optimize your code.
Tom SimmonsTom Simmons
Hi Subramani, could you please give me an example on how can I optimize this code? JSON data that is being returned is definetly less than 12 Mb however I`m not sure why this is happening..
@GM@GM
Hi Tom,

The response which you are getting from (req1.setEndpoint('https://test.samplepoint.com/api/accservices.svc/accountfeed');) is hitting the govt limit.

Optimize the code of that end point url(cls- accountfeed) and try to retrive less record in single transaction.

Regards,
GM