希望你在这些时候一切都好,下面是一个常见的场景,它获取一些 sObject 记录,执行一些处理,例如调用外部 REST 端点或执行一些计算,然后在数据库中异步更新它们。. 以下代码获取 Account 记录的集合,为每条记录设置 parentId,然后更新数据库中的记录。
我的问题是:-
A) Why i need to set the parentId for each record for Queueable Apex?
B) Why i cant use public identifier (mind you i know differences between public and private identifier :)) but why here we used private in Queueable Apex and then we have to set the values?
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;
}
}
来源:- https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_queueable