Is there a maximum result size for @AuraEnabled Apex methods for Lightning Aura components?

I tested three basic boundaries: total payload size, size of an element, and number of items.

Total Payload Size, Element Size

First, I created a map with 9 keys, each key being a 3,000,000 character string. This weighs in at just over 27 MB of data. Aura rendered the page in a couple of seconds, all elements present and accounted for.

Edit

If you use @AuraEnabled(cacheable=true), there's a 10 MB limit. In most cases, caching is desirable, but if you need a large amount of data, disabling caching can allow you to exceed this limit.

Large Number of Items

I then created a map consisting of 100,000 elements, but just smaller strings, weighing in at about 1.2 MB of JSON-ified data. This took much longer to render (aura:iteration doesn't like 100,000 items), but all the elements were present.


No, there doesn't appear to be a maximum size aside from whatever your bandwidth and memory can handle.


Edit: I just realized that this may be an issue with the volume of data you're querying--in Apex. See, if you query too many fields, you can cause the sub-query to be broken up into chunks with a QueryLocator. The threshold for this behavior depends on the number of fields you query.

Try using .size() on the value before returning the value, and see if you get an exception. If so, you'll need to write a wrapper class, then use a for-each loop to extract the children:

sObject[] children = new sObject[0];
for(sObject record: queryResult.childRelationship__r) {
    children.add(record);
}

I created a very simple component:

js controller:

({
    doInit : function (component, event, helper){
        var action = component.get("c.getAccountWithContacts");
        action.setCallback(this, function(response){
            console.log(response.getReturnValue());
        });
        $A.enqueueAction(action);
    }
})

Apex Controller

public class test {
    @AuraEnabled
    public static Map<String, Object> getAccountWithContacts() {
        List<Account> accounts = [
            SELECT Id, (
                SELECT Id
                FROM Contacts
            )
            FROM Account
            WHERE Name = 'Bulk Aura Test'
        ];

        return new Map<String, Object>{
            'accounts' => accounts,
            'accountsSize' => accounts.size(),
            'status' => 'success'
        };
    }
}

Component

<aura:component access="global" controller="test">
   <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
</aura:component>

I used this script to set up the data:

Account newAccount = new Account(Name = 'Bulk Aura Test');

insert newAccount;

List<Contact> newContacts = new List<Contact>();

for (Integer i = 0; i < 100; i++) {
    newContacts.add(new Contact(
        FirstName = 'test',
        LastName = string.valueOf(i) + 'Contact',
        AccountId = newAccount.Id
    ));
}

insert newContacts;

My debug

Debug

Conclusion

My instinct is that there is no hard limit on the size of the results. I'd put my money on something in the code causing the problem with such a limited sample I can't guarantee that either. Use the sample I posted but adapt it to pull in your record as that would give you a minimum viable code sample that you can reproduce the issue with and hopefully give us more information to help you.