Skip to main content
21 votes
Accepted

Reset an Aura attribute to a blank sObject type?

Add the following piece of code at the bottom of your controller: component.set("v.newItem",{'sobjectType':'Camping_Item__c', 'Name': '', 'Quantity__c': 0, ...
Shobhit Saxena's user avatar
17 votes
Accepted

How to send Javascript map as a parameter from lightning component to Apex server controller?

Don't use Map, just use a normal Object. Here's a demonstration: Apex: public class LightningMap { @AuraEnabled public static void doMap(Map<String, Object> values) { System.debug(...
sfdcfox's user avatar
  • 495k
15 votes

How do I start to debug my own Apex code?

I've added an Apex debugger to Illuminated Cloud that allows you to step through code, see variable values, etc. It uses information from debug logs and checkpoints to "replay" the executed process, ...
Scott Wells's user avatar
15 votes
Accepted

Pagination with Lightning Components

Pagination isn't accomplished server-side in Lightning; but instead done by client-side code. See my gist for an example that loads up to 50,000 rows. If you need more than that, you simply need to ...
sfdcfox's user avatar
  • 495k
14 votes

How to convert List to a Map?

You begin your question with: I have a List<custom_object__c>. I want to convert to a Map, where the ID is the String and the value to be an custom_object__c object. Then you show us code that ...
crmprogdev's user avatar
12 votes
Accepted

What is the $A object in lightning?

Yes, $A is how you gain access to the underlying Aura framework, such as enqueuing actions, getting application events, managing the Aura rendering life cycle, and various utility methods. You can ...
sfdcfox's user avatar
  • 495k
11 votes
Accepted

Why does my Lightning Component go into an infinite loop and fail to save?

The reason for the cause of the recursion is your apex method and the lightning component helper method have same name "save" I would change the apex method to different name than save save : ...
Mohith Shrivastava's user avatar
11 votes

How to fetch Custom Metadata Type record in apex and compare it with a string

From Spring 21 there is new way for accessing record inside Custom Metadata. Accessing specific record: ObjectName__mdt.getInstance('RecordName'); Accessing all records (and you can loop them): ...
Brane's user avatar
  • 1,052
10 votes
Accepted

How to get the class value from an attribute in lightning controller ?

There is $A.util hasClass function: var isExpandable = $A.util.hasClass(cmp.find("CollapseExpand"), "slds-show"); that you can use to check if a specific class is present.
Keith C's user avatar
  • 136k
9 votes
Accepted

Apex PageMessages are not displayed when using OnComplete JS for CommandButton

When you specify the oncomplete attribute, VF is going to perform a Javascript AJAX postback rather than a full page post back to Salesforce. In the full page postback scenario, the entire page is ...
Mark Pond's user avatar
  • 23k
8 votes

AssignTo variable in attribute

The attribute in the component is evaluated after the component's controller constructor runs. Within the constructor it will be null because it simply hasn't been evaluated yet. You can see it here ...
Mark Pond's user avatar
  • 23k
8 votes
Accepted

Why is the standard controller record if deleted in test class not reflect in the controller class

To answer you first question. Salesforce uses call by reference methodology. Thus Test class and main class are referring to same account memory instance. Whatever changes you make to the allocated ...
Pranay Jaiswal's user avatar
8 votes

Maintain state in Visualforce Page without using View State

The exact solution depends on the situation. You shouldn't think solutions as "either-or," as there's often an opportunity for hybrid solutions. There's also a few bonus solutions you can use ...
sfdcfox's user avatar
  • 495k
7 votes
Accepted

AssignTo variable in attribute

Yes, the value is null in the constructor-- the value is set sometime afterwards. Usually, I do something like this: public class RecordDisplayController { SObject theRecord; public void ...
sfdcfox's user avatar
  • 495k
7 votes

How do I start to debug my own Apex code?

The mechanics of how to get debugging information have been covered effectively in the other answers. This is more of a 'how-to fish guide' to use your metaphor. You start with a symptom of the ...
Arpi Jakab's user avatar
7 votes
Accepted

Controller object not updating fast enough

A good way to do that is to skip the method and use the basic visualforce setters. <apex:inputCheckbox value="{!myCheckboxValues[0]}"> <apex:actionSupport event="onchange" reRender="...
Fernando Gavinho's user avatar
7 votes

Controller object not updating fast enough

This is primarily due to network latency. When using apex:actionSupport, an ajax call is initiated to the server. These calls are non-blocking, meaning you can initiate several, completely ...
S Morgan Robertson's user avatar
7 votes
Accepted

AutoSave information every 5 minutes- How to implement?

You can use <apex:actionPoller/> to implement your requirement Visualforce <apex:page controller="autoSaveController"> <apex:form id="form1"> <apex:actionPoller action="{!save}"...
Santanu Boral's user avatar
7 votes
Accepted

Redirect to another VF page while using a Same Controller?

The page's view state is preserved when the following conditions hold: The new page uses the same controller as the old page. The new page uses a subset of the extensions as the old page. The ...
sfdcfox's user avatar
  • 495k
7 votes
Accepted

Visualforce page controller confusion

First of all, only StandardController will not serve your purpose. So, go for StandardController will ControllerExtension, which means it will extend the functionalities of StandardController (will ...
Santanu Boral's user avatar
6 votes
Accepted

how to call another visualforce page from an apex command button

Put the below code in the controller action method that is being called on click of command button PageReference pr = new PageReference('/apex/yourVFPageName'); pr.getParameters().put('key','value'); ...
Saumya Ranjan Satapathy's user avatar
6 votes

Apex Controllers: What do the get; set; do?

This excerpt is taken from Learning Apex Programming, by Matt Kaufman. In order for an Apex class to function as a controller for a Visualforce page, the variables and methods in the class need to ...
Andy Hitchings's user avatar
6 votes

How do I start to debug my own Apex code?

Following up on the other answers, if you do use System.Debug and you use VSCode, you can view the debug statements in real time via the terminal. Execute this command in the VSCode terminal window (...
Shanerk's user avatar
  • 1,076
6 votes
Accepted

Error Logging Utility and Controllers

If you're looking for a mechanism that will allow you to save errors from within a constructor, you will have to enqueue them, and then later flush the queue. You might consider an abstract class that ...
Adrian Larson's user avatar
  • 150k
6 votes

Why is the standard controller record if deleted in test class not reflect in the controller class

Both the test and controller are running in the same execution environment so a reference to an object modified by one will be seen by the other. The data is in memory that both access. In addition, ...
Keith C's user avatar
  • 136k
6 votes
Accepted

lightning callback not firing

According to this post, "a javascript method name in a component controller can never be the same name in an apex lightning controller": Enqueued action not executed in Lightning Component Just need ...
Instread's user avatar
  • 633
6 votes
Accepted

SOQL ORDER BY on a text field, but not alphabetically - is this possible?

Change type of field Incident_Type__c to picklist, then arrange values in desired order Outage, Maintenance, Public Holiday and values would be sorted in that way. From documentation : picklist ...
Oleksandr Berehovskyi's user avatar
6 votes
Accepted

What is the difference between page and component controller?

A component controller is the Apex controller of a Visualforce component, a reusable unit of functionality that can be embedded in one or several Visualforce pages. The page controller is the Apex ...
David Reed's user avatar
  • 93.2k
6 votes
Accepted

ltng require scripts not working for me!

Your scripts from <ltng:require> are not guaranteed to be available in your component's init handler. They are loaded asynchronously. You need to add the attribute afterScriptsLoaded="{!c....
David Reed's user avatar
  • 93.2k
6 votes
Accepted

How can I make a lightning component change as the underlying data changes without refreshing?

Very very interesting question. Using Platform Events and lightning:empAPI : This can be solved by Platform events, whenever a player makes a move, fire a platform event. Also as a listener use ...
Pranay Jaiswal's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible