You need to sign in to do that
Don't have an account?

need to pass sobject parameters to queueable
I need to pass sobject as parameter using trigger to queuebale and have written below code, but facing error as
Variable does not exist: Name
Variable does not exist: id
Constructor not defined: [ContactCreationQueueable].<Constructor>(List<Account>)
Queueable class:
public class ContactCreationQueueable implements Queueable{
private List<Account> acctListToCreateContacts;
public ContactCreationQueueable(List<Account> expectingListOfAccountsFromTrigger){
this.acctListToCreateContacts=expectingListOfAccountsFromTrigger;
}
public void execute(QueueableContext Qc){
List<Contact> conListToInsert = new List<Contact>();
for(Account acct : acctListToCreateContacts){
Contact con = new Contact();
con.LastName = acct.Name;
con.AccountId = acct.id;
conListToInsert.add(con);
}
insert conListToInsert;
}
}
Trigger code :
Trigger AccountTrigerForContacts on Account (after insert) {
if(Trigger.isAfter && Trigger.isInsert){
System.enqueueJob(new ContactCreationQueueable(Trigger.new));
}
}
Please help in resolving this error.
Variable does not exist: Name
Variable does not exist: id
Constructor not defined: [ContactCreationQueueable].<Constructor>(List<Account>)
Queueable class:
public class ContactCreationQueueable implements Queueable{
private List<Account> acctListToCreateContacts;
public ContactCreationQueueable(List<Account> expectingListOfAccountsFromTrigger){
this.acctListToCreateContacts=expectingListOfAccountsFromTrigger;
}
public void execute(QueueableContext Qc){
List<Contact> conListToInsert = new List<Contact>();
for(Account acct : acctListToCreateContacts){
Contact con = new Contact();
con.LastName = acct.Name;
con.AccountId = acct.id;
conListToInsert.add(con);
}
insert conListToInsert;
}
}
Trigger code :
Trigger AccountTrigerForContacts on Account (after insert) {
if(Trigger.isAfter && Trigger.isInsert){
System.enqueueJob(new ContactCreationQueueable(Trigger.new));
}
}
Please help in resolving this error.