解决Salesforce上的Batch限制问题(salesforce Apex Batch Governor)

Keyword:salesforce Apex Batch Governor
解决Salesforce上的Batch限制问题
通过Schedulable来调整每次登陆的数量,进而规避Salesforce的限制。
例如:

global class doUpsertStudentBatch implements Schedulable {

    //每次ExecuteMethod处理的件数设定
    private final Integer BATCH_SIZE = 100;

    //Batch执行
    global void execute(SchedulableContext ctx) {

        //想要处理的对象,通过SOQL对其进行查询,并取出相关的信息
        String SOQL = 'SELECT Name__c,  '
                           + 'Class__c,  '
                           + 'Grade__c,  '
                           + 'Zhongwen__c, ' 
                           + 'English__c  '
                           + 'FROM STUDENT__c WHERE Sex__c=\'MAN\'';
        UpsertStudentsBatch b = new UpsertStudentsBatch(SOQL);
        Database.executeBatch(b, BATCH_SIZE);
    }
}

 

public class UpsertStudentsBatchimplements Database.Batchable, Database.Stateful {

 

   private Integer recordCount {get; set;}

 

   public UpsertStudentsBatch () {

 

       this.recordCount = 0;

    }

 

   public Database.QueryLocator start(Database.BatchableContext BC) {

          return Database.getQueryLocator(query);

    }

 

   public void execute(Database.BatchableContext BC, Listscope) {

       for (Contact cont : scope) {

           cont.Class__c = '五年级';

           this.recordCount++;

 

        }

       update scope;

    }

 

   public void finish(Database.BatchableContext BC) {

 

    }

 

}

 

你可能感兴趣的:(salesforce,Apex,Batch)