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
Nick VerschuerenNick Verschueren 

Exception during callout: IO Exception with Navision

We have an integration for sending invoces to Navision. 
At the moment of invocing the WebserviceCallout We get the "Exception during callout: IO Exception: Exceeded max size limit of 12000000" Error...

The export does succeed, the invoice and file are uploaded in Navision

I've been trying to find the reason by checking heap sizes but I can't find why I get this error or how to fix it.

this is the method that keeps failing

public NavImport.SalesInvoices ImportSalesInvoices(NavImport.SalesInvoices mySalesInvoice) {
            IIBP.DebugLog asyncLogs = new IIBP.DebugLog('Start ImportSalesInvoices');
            asyncLogs.addDebugLog('heap size:' + limits.getHeapSize());
            NavImportCodeUnit.ImportSalesInvoices_element request_x = new NavImportCodeUnit.ImportSalesInvoices_element();
            request_x.mySalesInvoice = mySalesInvoice;
            NavImportCodeUnit.ImportSalesInvoices_Result_element response_x;
            Map<String, NavImportCodeUnit.ImportSalesInvoices_Result_element> response_map_x = new Map<String, NavImportCodeUnit.ImportSalesInvoices_Result_element>();
            response_map_x.put('response_x', response_x);
            asyncLogs.addDebugLog('heap size:' + limits.getHeapSize());
            try{
                WebServiceCallout.invoke(
                    this,
                    request_x,
                    response_map_x,
                    new String[]{endpoint_x,
                    'urn:microsoft-dynamics-schemas/codeunit/ImportWSManagement:ImportSalesInvoices',
                    'urn:microsoft-dynamics-schemas/codeunit/ImportWSManagement',
                    'ImportSalesInvoices',
                    'urn:microsoft-dynamics-schemas/codeunit/ImportWSManagement',
                    'ImportSalesInvoices_Result',
                    'NavImportCodeUnit.ImportSalesInvoices_Result_element'}
                  );
            }
            catch (Exception e) {
                asyncLogs.addErrorLog('Exception during callout: ' + e.getMessage());
            }
            asyncLogs.addDebugLog('heap size:' + limits.getHeapSize());
            response_x = response_map_x.get('response_x');
            asyncLogs.addDebugLog('heap size:' + limits.getHeapSize());
            asyncLogs.flush();
            return response_x.mySalesInvoice;
        }
And this is the debug result
2023-08-30 11:31:19 | DEBUG | Start ImportSalesInvoices
2023-08-30 11:31:19 | DEBUG | heap size:5817
2023-08-30 11:31:19 | DEBUG | heap size:6157
2023-08-30 11:31:22 | ERROR | Exception during callout: IO Exception: Exceeded max size limit of 12000000
2023-08-30 11:31:22 | DEBUG | heap size:6451
2023-08-30 11:31:22 | DEBUG | heap size:6541

Can anyone help me fix this issue? Everything arrives fine in Navision but I can't see this in Salesforce since I always get this error, so following code does not executed properly and invoices remain "unsent" in our SF.
HarshHarsh (Salesforce Developers) 
Hi Nick,
  • This error message is due to the maximum size of the call-out response which is 12MB. This error is typical because of the maximum allowed heap size (6MB sync / 12MB async).
  •  I would like to mention that the limit for both max sizes of call out (request and response ) and heap size is 12MB. 
Please follow the below links for the best practices for running within the Apex heap size : Please mark it as Best Answer if the above information was helpful.

Thanks.