8

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.

8

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);
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.