I’m playing around with Queueable class to possibly implement in a upcoming project.
Here is what am trying to do.
I have a Queueable class.
public class SampleQueueble implements Queueable { public static List<String> sampleC = new List<String>(); public SampleQueueble(List<String> objList){ sampleC.addAll(objList); system.debug('sampleC->'+sampleC); system.debug('objList->'+objList); } public void execute(QueueableContext context) { system.debug('sampleC ->'+sampleC); } }
And I’m calling it as follows, where I want to pass a List to a Queueable class. And here’s how I call it.
public List<String> listS = new List<String>(); listS.add('abz'); listS.add('aqz'); listS.add('aez'); listS.add('atz'); system.debug('listS->'+listS); ID jobID = System.enqueueJob(new SampleQueueble(listS)); system.debug('listS->'+listS); system.debug('jobID ->'+jobID);
But I cannot retrieve the listS
List on the Queueable
class even though I pass it together with the constructor. It simply doesn’t call the constructor.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Couple things. You need the List<String>
to be an instance property, not a static
one. I would also move the instantiation to reside solely in the constructor.
public class SampleQueueble implements Queueable { public final List<String> data; public SampleQueueble(List<String> input) { data = input; } public void execute(QueueableContext context) { system.debug('data ->'+data); } }
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0