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
Jefferson FernandezJefferson Fernandez 

Multiple Apex Queries on One JS DoInit Controller Lightning Components

Hi All,
I need to fetch data from multiple apex methods which yield separate and different lists of objects but I only have one DoInit function and one possible object to be passed to $A.enqueueAction(action). If i call the enqueueAction several times each for a different object, it malfunctions.

Can you think of any solution where I can call different methods on the same class and also set different attributes on my components once the data has returned? without the need of havingg to separate each methods to have its own component. I just created one component just for demo purposes to the client and i want to have it worked the soonest. TIA
Mathew Andresen 5Mathew Andresen 5
Unless I'm missing something this is where the helper component comes in.  So you have one init function on your main component, and then that will call multiple functions on the helper class.
sfdcMonkey.comsfdcMonkey.com
hi Jefferson Fernandez 
here is a trick for you
create property in your controller class and set value to property in singel class method and return the whole class .
now you don't  need to create multiple aura:attribute you can access data from direct class type attribute
go to below like for it
https://teachforce.wordpress.com/2016/11/17/how-to-access-apex-class-property-in-lightning-component/
i hope it solve you problem
let me inform if it helps you
thanks
Mathew Andresen 5Mathew Andresen 5
Hi Plush_Soni

That is a very good solution, I didn't realize you could access the variables like that the same way you can in visualforce.  This should prove super helpful

Thanks,