In my Lightning Component, I'm doing a very simple call to server side action which is executed when you click on a button, here's an example:

  getCustomObjects: function(component) {
    var action = component.get('c.getCustomObjects');

    action.setCallback(this, function(response){
        var state = response.getState();
        if (state === 'SUCCESS') {
            component.set('v.CustomObjects', response.getReturnValue());


I then have an APEX controller, that does a simple query to return all Custom Objects in our records. Like below:

public with sharing class CustomObjectController {

  public static List getCustomObjects() {
      List<CustomObject__c> objects = [SELECT Id, object_name__c FROM CustomObject__c];

    return objects;

When I press the button to execute the getCustomObjects method, response.getReturnValue() returns undefined and it seems it gets stuck in an infinite loop and then crashes with the error below:

enter image description here

My example is based from this article and I'm not sure what I'm doing wrong or what checks I have to do to see why this is happening. Performing the query in the Developer Console returns all the records that I need.


1 Answer 1


The problem is the name of the variables here .Be always careful with naming your actions on the server and the client side .

getCustomObjects: function(component) {
   var action = component.get('c.getCustomObjects');

So your above code your actions name is getCustomObjects and your JS controller name is also getCustomObjects .

This will create an internal recursion leading to calling server side actions again and again and setting the attribute value clearly hitting the browser stack size .

Change the name of the controller at client site to this

getClientCustomObjects: function(component) {
   var action = component.get('c.getCustomObjects');

The recursion can happen in javascript as well and below is a sample code that can cause stack hit .The similar thing is happening in this scenario

(function a() {
 })();//This can cause stack size exception
  • Thank you, Mohith. That worked. That seems like a gotcha to me. I'm not sure if I have read this somewhere and just forget or maybe it's something that hasn't been explained in the docs.
    – kev_panda
    Oct 25, 2016 at 19:49
  • Its not in docs and somethings come by experience and using salesforce stackexchange website :) .Glad you posted and glad i tried and figured the root cause Oct 25, 2016 at 19:52
  • Mohit, when you are referring heap size are referring apex heap size?
    – Praveen
    Oct 25, 2016 at 20:28
  • No the browser stack and not the apex . Oct 25, 2016 at 20:29
  • Ok.But I don't think the problem is due to hitting heap size in the browser, it's primarily due to client side controller function being stacked up and called infinitely(recursively as you mentioned) which inturn hits the browser call stack limit.
    – Praveen
    Oct 25, 2016 at 20:35

Not the answer you're looking for? Browse other questions tagged .