function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sachin Bhalerao 17Sachin Bhalerao 17 

use of response.getReturnValue() in Lightning component?

Dear Team ,

Greetings !!!

I write a code to pull data on datatable in Lightning component . On Helper.js file i write following code :

  action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                // Alert the user with the value returned
                // from the server

                component.set("v.acctList", response.getReturnValue());
            }
        });

I am unable to unserstand how  response.getState(); works and how   component.set("v.acctList", response.getReturnValue()); works .

Please describe me in wasy way how response.getReturnValue() gets populated .

Thanks & Regards
Sachin Bhalerao
Team NubesEliteTeam NubesElite
Hi Sachin,
t is a JavaScript object - the JSON has already been parsed.
To inspect simple JavaScript objects use JSON.stringify:
console.log('currency data is:' + JSON.stringify(actionResult.getReturnValue()));
This will walk around the object graph - across arrays and nested objects - and output each object found in string format.
(The server takes Apex objects, turns them into JSON strings, sends them to the client, then the client turns the JSON into JavaScript objects that are passed to your code. For this debugging you are just flipping back to JSON to view the data.)
Another way of looking at the data sent to the server and returned from the server is to use your browser's Network tab in its Developer tools. There you can see the data that is sent and received, and by looking through the multiple requests find the right ones and pick out the JSON that is transmitted.
If the JSON is large, you can cut and can paste it into a formater e.g. JSON Formatter & Validator to more easily examine it.

Thank You
www.nubeselite.com
Development | Training | Consulting


Please mark this as solution if your problem resolved.
 
Deepali KulshresthaDeepali Kulshrestha
Hi Sachin,



You must be calling Apex controller from your lightning controller like this:

var action = component.get("c.getWrapperItems");

        action.setCallback(this, function(response)

                           {

                               var state = response.getState();

                               if (component.isValid() && state === "SUCCESS")

                               {

  // Alert the user with the value returned

                // from the server



                   component.set("v.acctList", response.getReturnValue());

}

getState method is used to check the status of connection between your server side controller and client side controller. It returns SUCCESS if the connection is established successfully.



We use 'v.your_attribute_name' in front of those attributes that are present on the lightning component's component page. You must have an attribute with the name 'acctList'.

and in the setCallback method, we define what to do with the data that is returned by the apex controller. Here component.set method is used to set the returned value to this attribute.



I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.



Thanks and Regards,

Deepali Kulshrestha

www.kdeepali.com