Lightning Components Tip: Don’t mess with Method names

In 2014, Salesforce introduced the front-end platform called Lightning. The the next generation CRM platform provides functionality to help customers close deals faster and smarter. Sales teams now can see and present data to their customers and potential customers in visualized ways.

What Is Lightning?

Lightning is a component-based framework. It allows components to be reused in different places within an organization. Therefore, admins can quickly customize pages for different needs from various users.

When it comes to lightning component development, lightning makes it easier and faster for developers to build and debug applications using front end tools. Three basic elements of lightning components are

  1. Aura component,
  2. Front end controller (JavaScript)
  3. Back end controller (Apex).

Here, JavaScript controller acts as the main controller to process business logic and Apex controller is more like database interpreter to query data from Salesforce Database.


However, when many methods have same actions, naming problems come in. The action methods in Apex return some data that are normally are declared in the format getVariableName.

Similarly, in lightning, JavaScript methods in JS controller usually are declared in the same way, getVariableName to get data from Apex controller. Inside JS methods, an action variable is declared to retrieve data from Apex controller, which often is named getVariableName.

This action will be put on a queued action list. Here is a screenshot how it looks.

In JS Controller

In JS Controller

In Apex Controller

As a result, it creates an infinite loop which keeps firing getStrings function. The reason is that the queued action list has taken the method name, not the action variable. The queued action list fires getStrings function, inside the function, a statement puts function again into the list, and so on.

To avoid this problem, JS functions in JS controller can be named as getVariableNameFunction. Inside the functions, query action variables can then be named as getVaribleNameAction. By doing this, normal naming convention remains the same and can avoid confusion for Lightning framework when picking the actions up.

JS Controller

“We @ Techforce Services are specialized in Salesforce Development – Apex, Visualforce and Lightning, API Integrations. We also cover Salesforce Setup, Implementation & Customization”.

Table of Contents

Talk to our Salesforce Experts.