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
Gareth NguyenGareth Nguyen 

Constructor not Defined - Enqueue

Hi guys,

I am having an issue when trying to implement Enqueue. The error says that the constructor is not defined.
Constructor not defined: [job1].<Constructor>(List<Account>)
I have a trigger that enqueues a class:
trigger CreateAccount on object (before insert) { 
        if (Trigger.isBefore && Trigger.isInsert) { 
                   System.enqueueJob(new job1(Trigger.new)); 
        } 
}
Here is the class that I am devloping:
public class job1 implements Queueable{ 
          public static void job1 (List<Account> Acc) { 

          } 

          public void execute(QueueableContext abcs) { 
                   actions .... 
          }
}

How can I fix this error?

Thank you.
AnudeepAnudeep (Salesforce Developers) 
Hi Gareth, 

I recommend calling enqueueJob like this
public class UpdateParentAccount implements Queueable {
    private List<Account> accounts;
    private ID parent;
    public UpdateParentAccount(List<Account> records, ID id) {
        this.accounts = records;
        this.parent = id;
    }
    public void execute(QueueableContext context) {
        for (Account account : accounts) {
          account.parentId = parent;
          // perform other processing or callout
        }
        update accounts;
    }
}
 
// find all accounts in ‘NY’
List<Account> accounts = [select id from account where billingstate = ‘NY’];
// find a specific parent account for all records
Id parentId = [select id from account where name = 'ACME Corp'][0].Id;
// instantiate a new instance of the Queueable class
UpdateParentAccount updateJob = new UpdateParentAccount(accounts, parentId);
// enqueue the job for processing
ID jobID = System.enqueueJob(updateJob);

Unsure if System.enqueueJob(new job1(Trigger.new)); is going to work. Maybe you should try passing a List<Account> instead

See Control Processes with Queueable Apex

Let me know if this helps, if it does, please close the query by marking it as solved. It may help others in the community. Thank You!
sfdc1.3890582999007844E12sfdc1.3890582999007844E12
@Anudeep  this works and should be marked as answered.