How do I pass a value from one method to another. I am using a public list with a {get; set;} but this seems not to be working. What I want to achieve is to loop trough the insert from the first method in the second method.
Code sample
public without sharing class addController {
public List<Contact> contactList {get; set;}
@AuraEnabled
public static void saveContacts(List<Contact> listContact){
Insert listContact;
contactList= listContact;
...
}
@future
public static void createUser(){
for(Contact con : contactList){
.. }
}
}
Best Answer
The trick you're trying to use would work, except that a future method, being called in a separate transaction, won't remember the contactList from the first transaction. This is because the data is not serialized as part of calling the future method.
Instead, you have to use a parameter to pass the data in to the method:
However, as you've probably realized by now, future methods don't support this syntax (only primitives and collections of primitives are allowed), so you need to pass in the ID values you got from the first step:
To get this collection efficiently, just create a Map from the results of your insert: