首页 > 代码库 > 59、salesforce实现数据的批量处理

59、salesforce实现数据的批量处理

批处理,往自己的邮箱发一封邮件,批处理采用异步的处理方式处理数据,最多可以处理5000万条数据

global with sharing class MerchandiseBatch implements Database.Batchable<sObject>,Database.Stateful{ Integer queryCount = 0; String myEmailAddress = ‘weizhen.zhao@pactera.com‘; global Database.QueryLocator start(database.BatchableContext bc){ String query = ‘select Name from Merchandise__c‘; return Database.getQueryLocator(query); } global void execute (Database.BatchableContext bc,List<Merchandise__c> merchandiseList){ for(Merchandise__c merchandise : merchandiseList){ Decimal price = merchandise.Price__c; price += 1; queryCount +=1; } upsert merchandiseList; } global void finish(Database.BatchableContext bc){ System.debug(‘query count: ‘+ queryCount); Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); email.setToAddresses(new String[]{myEmailAddress}); email.setSubject(‘show count‘);//set subject email.setHtmlBody(‘query Count‘ + queryCount); Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email}); } }
MerchandiseBatch merchandise = new MerchandiseBatch();
Id batchId = Database.executeBatch(merchandise);

技术分享

 

59、salesforce实现数据的批量处理