You need to sign in to do that
Don't have an account?
SFDC Forum 9
List value from another method
Here I am planning to use the list value from one method to another, but i am getting null value, how can i get it, please suggest ASAP
public class RPC
{
@AuraEnabled public static List<Contact> contlist {get;set;}
@AuraEnabled
public static getContact(Id firstcontId){
List <Contact> contlist=[select Id, AccountID, Name, LastName, FirstName, Ind_ID__c, from Contact LIMIT 5];
}
@AuraEnabled public static String getRefreshInfo()
{
system.debug(contlist); ---//It gives me null value, how can i get the contlist from getContact and use it here
}
}
public class RPC
{
@AuraEnabled public static List<Contact> contlist {get;set;}
@AuraEnabled
public static getContact(Id firstcontId){
List <Contact> contlist=[select Id, AccountID, Name, LastName, FirstName, Ind_ID__c, from Contact LIMIT 5];
}
@AuraEnabled public static String getRefreshInfo()
{
system.debug(contlist); ---//It gives me null value, how can i get the contlist from getContact and use it here
}
}
Please try like this, This way you'll be storing the list from the first method to the global list and it can be accessed in any other method.
I tred suggested way, it did not help.please sugest to analyse this further
The global list is supposed to have the values until the class has executed successfully.
When you make a call to apex controller method from the component, they are being called from different instances. So the values you hold in the global list will be lost after the method have executed successfully. So you can't hold the values like that.
Instead you can return the list to your helper and store it in an attribute,
next time when you need to get updated values from the database you make the call to the method again.
I am calling it from lighting js controller.
Whats happening is, as soon as component loads, through 'init', it will call 'someX'apex method and it will call some other methods internally and in between this process, my list is used to query data.
My requirement is, when i click on lightnin button, will call some another js function which in turn call the another apex method, there I will have to use this same list.
I have used some process as suggested from the values of intial method (someX)(getting retun vaue and saving in attribute and stuff).
Sincce this conlist is used somewhere in between , i am not getting how to get it to helper.please suggest the syntax or the way.
Thank you so much again
And returning the list to your component is easy too.
You can refer here (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm) and if any problem occurrs post them here.