APEX Controller parameters size (bytes) limit in Lightning component

I have an @AuraEnabled method in my APEX controller that have a lot of parameters:

  @AuraEnabled
  public static String sendEmail(
    String    toAddresses,
    String    ccAddresses,
    String    bccAddresses,
    String    fromAddress,
    String    subject,
    String    content,
    String    attachments,
    String    externalAttachments,
    String    staticFiles,
    String    dynamicFiles
  ) {} 

where externalAttachments is an array of objects (serialized) like this: [{ type: '', name: '', data: /*base64 data*/ '' }]

const payload = {
    fromAddress: '',
    toAddresses: JSON.stringify([]),
    ccAddresses: JSON.stringify([]),
    bccAddresses: JSON.stringify({}),
    subject: subject,
    content: contentEml,
    attachments: JSON.stringify([]),
    externalAttachments: JSON.stringify(filesCust),
    staticFiles: JSON.stringify([]),
    dynamicFiles: JSON.stringify([])
};

I used to work this way but since today, when there is a externalAttachment, the action (in JS controller) is fired and the callback is always called with a state of error but the server never received a request (in my logs).

Is there (until ?) a size limit, in byte, for the Lightning Controller <-> APEX Controller payload ?

Answer

Whatever limit there is or isn’t between the client and server, within the server Apex method the normal governor limits apply. So if your @AuraEnabled method is receiving several megabytes of base64 data and then tries to turn that data into a different format and so consume more big chunks of heap you will be at risk of hitting the 6M byte heap limit.

Attribution
Source : Link , Question Author : Simonp , Answer Author : Keith C

Leave a Comment