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
Jonathan SpinkJonathan Spink 

How do I send parameters to a queueable class?

I want to launch my code as a queueable class, but I need to include a parameter. I have tried doing this but at some point I have to make a call that doesn't include parameters, i.e.

public void execute(QueueableContext context) {...
}

Is there any way round this?
 
Best Answer chosen by Jonathan Spink
kirellos malakkirellos malak

You can pass paramters you want to the class constructor for example

public class CreateCustomObject implements Queueable {
           private String customObjectName;
           public CreateCustomObject (String name) {
                      this.customObjectName = name;
           }
           public static void functionToFire (String name) {
                     // Do something with name
           }
           public void execute(QueueableContext context) {
                    functionToFire(customObjectName);
           }
}

All Answers

SwethaSwetha (Salesforce Developers) 
HI Jonathan,
Recommend reviewing https://salesforce.stackexchange.com/questions/286463/queuable-apex-logic-in-constructor-or-execute-method

Related:https://github.com/BobHatcher/QueueableUtilities/tree/master/MyQueueable/src/classes

If this information helps, please mark the answer as best. Thank you
Jonathan SpinkJonathan Spink
Thanks for your help. I'm not sure it directly answers my question but it's of interest. Jonathan
kirellos malakkirellos malak

You can pass paramters you want to the class constructor for example

public class CreateCustomObject implements Queueable {
           private String customObjectName;
           public CreateCustomObject (String name) {
                      this.customObjectName = name;
           }
           public static void functionToFire (String name) {
                     // Do something with name
           }
           public void execute(QueueableContext context) {
                    functionToFire(customObjectName);
           }
}
This was selected as the best answer
Jonathan SpinkJonathan Spink
Thanks Kirelios.