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
farah sheriffarah sherif 

please explain the below code


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;
}
}
Best Answer chosen by farah sherif
Meghna Vijay 7Meghna Vijay 7
Hi Farah,
It's a queueable class and in the constructor you see two parameters which is List<Account> records -> Account records and Id id -> ParentId . And in execute method account records ParentId field is set with the ParentId which is being sent from some other class in the form of System.enqueueJob(new UpdateParentAccount (records, '001xxxxxxxx')) and then those records are updated via performing a DML operation.
If you want to perform callout make sure you implement Database.callouts interface.
Hope it clears.
Thanks

All Answers

Meghna Vijay 7Meghna Vijay 7
Hi Farah,
It's a queueable class and in the constructor you see two parameters which is List<Account> records -> Account records and Id id -> ParentId . And in execute method account records ParentId field is set with the ParentId which is being sent from some other class in the form of System.enqueueJob(new UpdateParentAccount (records, '001xxxxxxxx')) and then those records are updated via performing a DML operation.
If you want to perform callout make sure you implement Database.callouts interface.
Hope it clears.
Thanks
This was selected as the best answer
Raj VakatiRaj Vakati

It's a queueable class and in the constructor you see two parameters which is List<Account> records and one id of the parent record to be updated  .. I you execut the below code from developer console you can able to see the all list of accounts are updated with parent account

 
// 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);