Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Salesforce 创建批处理顶点以更新多个对象_Salesforce_Apex Code_Salesforce Communities - Fatal编程技术网

Salesforce 创建批处理顶点以更新多个对象

Salesforce 创建批处理顶点以更新多个对象,salesforce,apex-code,salesforce-communities,Salesforce,Apex Code,Salesforce Communities,我已经有了一个Schedule apex,它可以在3个对象上进行基本的查询和更新。我想让这个班级成批上课。但无法在批处理apex中添加多个对象并围绕它们循环 下面是我的日程安排 `global class scheduleWorkday implements Schedulable { global void execute(SchedulableContext ctx) { //Get Accounts List<Account> getbdayacco

我已经有了一个Schedule apex,它可以在3个对象上进行基本的查询和更新。我想让这个班级成批上课。但无法在批处理apex中添加多个对象并围绕它们循环

下面是我的日程安排

`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;


}



}


}`
`全局类scheduleWorkday实现可调度{
全局无效执行(SchedulableContext ctx){
//记帐
List getbdayaccount=[从State=CT的帐户中选择ID、名称、地址];
如果(!getbdayaccount.isEmpty()){
对于(帐户a:GetBdayaAccount){
a、 名称='测试';
a、 州='NJ';
}
更新getbdayaccount;
}
//获得线索
List getPreApprovalFollow=[选择ID、名称、状态、LeadSource from Lead,其中状态='CT'];
如果(!getPreApprovalFollow.isEmpty()){
对于(Lead l:getPreApprovalFollow){
l、 LeadSource=‘转介’;
l、 州='NJ';
}
更新getPreApprovalFollow;
}
//获得机会
List getopps=[选择Id、CloseDate、Lead的状态,其中状态='CT'];
如果(!getopps.isEmpty()){
对于(机会o:getopps){
o、 CloseDate=Date.Today();
o、 State='CT';
}
更新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){

    }
}
全局类LeadProcessor实现数据库。可批处理{
//启动方法
global Database.QueryLocator启动(Database.BatchableContext bc){
String Query='Select id,LeadSource,State from Lead,其中State='CT';
返回数据库.getQueryLocator(查询);
}
//执行方法
全局void execute(Database.BatchableContext bc,列表范围){
对于(领导l:范围){
l、 LeadSource='Reference';
l、 州='NJ';
}
更新范围;
}
//完成方法
全局void完成(Database.BatchableContext bc){
}
}

如何更改此批处理顶点以返回多个查询、添加循环并更新它们

批处理Apex不是这样工作的。您可以在批处理作业中只迭代一个查询

因为您正在以三种不同的方式变异三个不同的对象,所以批处理链接和使用动态SOQL的选项在这里并不真正适用。您只需要构建三个不同的批处理类

您可以并行运行这些类,或者在其
finish()
方法中将每个类链接到下一个类。但你不可能一次完成所有的工作