Activity Forums Salesforce® Discussions What is the use of setcallback() method in lightning components in Salesforce?

  • chanchal kumar

    Member
    July 18, 2018 at 3:42 pm

    hello shradha,

    setcallback() method is used to call the method in server-side controller.

  • shariq

    Member
    September 19, 2018 at 1:50 am

    Hi,

    Basically, the setCallback() function sets a function to run after the action finishes. You might be wondering why we can't just call getReturnValue() on the action right after enqueuing it and why the setCallback() function is even necessary.

    setCallback() has a third parameter that registers the action state that will invoke the callback. If you don't specify the third argument for setCallback() , it defaults to registering the SUCCESS and ERROR states. To set a callback for another state, such as ABORTED , you can call setCallback() multiple times with the action state set explicitly in the third argument. For example:

    action.setCallback(this, function(response) { ...}, "ABORTED");

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos