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

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

global with sharing class MerchandiseBatch implements Database.Batchable,Database.Stateful{ Integer queryCount = 0; String myEmailAddress = '[email protected]'; 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 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实现数据的批量处理_第1张图片

 

转载于:https://www.cnblogs.com/weizhen/p/6407573.html

你可能感兴趣的:(59、salesforce实现数据的批量处理)