我已经有一个 Schedule 顶点,它适用于 3 个对象以执行基本查询和更新。我想做这门课。但无法在 Batch 顶点中添加多个对象并围绕它们循环。
这是我的日程表顶点的样子
`global class scheduleWorkday implements Schedulable {
global void execute(SchedulableContext ctx) {
//Get Accounts
List<Account> getbdayaccount = [Select ID, Name, Address from Account where State= CT];
if(!getbdayaccount .isEmpty()) {
for(Account a : getbdayaccount ) {
a.name = 'Test';
a.State= 'NJ';
}
update getbdayaccount ;
}
//get Leads
List<Lead> getPreApprovalFollow = [Select ID, Name, State, LeadSource from Lead where State = 'CT' ];
if(!getPreApprovalFollow .isEmpty()) {
for(Lead l: getPreApprovalFollow ) {
l.LeadSource = 'Referral';
l.State = 'NJ';
}
update getPreApprovalFollow ;
}
//get Opportunities
List<Opportunity> getopps = [Select Id, CloseDate, State from Lead where State = 'CT'];
if(!getopps.isEmpty()){
for(Opportunity o : getopps){
o.CloseDate = Date.Today();
o.State = 'CT';
}
update get opps;
}
}
}`
我尝试制作像这样的批处理顶点 -
global class LeadProcessor implements Database.Batchable <SObject> {
//START METHOD
global Database.QueryLocator start(Database.BatchableContext bc){
String Query='Select id,LeadSource, State from Lead where state = 'CT';
return Database.getQueryLocator(Query);
}
//EXECUTE METHOD
global void execute(Database.BatchableContext bc, List<Lead> scope){
for(Lead l: scope){
l.LeadSource='Referral';
l.State = 'NJ';
}
update scope;
}
//FINISH METHOD
global void finish(Database.BatchableContext bc){
}
}
如何更改此批处理顶点以返回多个查询、添加循环并更新它们。