当前位置:K88软件开发文章中心编程语言非主流编程语言Apex → 文章内容

Apex - 批量处理

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-15 16:31:01

详细信息页面安排Apex类,以及如下: 第1步:转到Setup => Apex类,单击Apex类。 第2步:点击Schedule Apex按钮: 第3步:提供详细信息: 第4步:然后点击保存按钮,您的类将被安排。 使用可调度接口计划Apex Batch作业//Batch Job for Processing the Recordsglobal class CustomerProessingBatch implements Database.Batchable<sobject>{ global String [] email = new String[] {'test@test.com'};//Add here your email address here //Start Method global Database.Querylocator start (Database.BatchableContext BC) { return Database.getQueryLocator('Select id, Name, APEX_Customer_Status__c, APEX_Customer_Decscription__c From APEX_Customer__c WHERE createdDate = today AND APEX_Active__c = true');//Query which will be determine the scope of Records fetching the same } //Execute method global void execute (Database.BatchableContext BC, List<sobject> scope) { List<apex_customer__c> customerList = new List<apex_customer__c>(); List<apex_customer__c> updtaedCustomerList = new List<apex_customer__c>();//List to hold updated customer for (sObject objScope: scope) { APEX_Customer__c newObjScope = (APEX_Customer__c)objScope ;//type casting from generic sOject to APEX_Customer__c newObjScope.APEX_Customer_Decscription__c = 'Updated Via Batch Job'; newObjScope.APEX_Customer_Status__c = 'Processed'; updtaedCustomerList.add(newObjScope);//Add records to the List System.debug('Value of UpdatedCustomerList '+updtaedCustomerList); } if (updtaedCustomerList != null && updtaedCustomerList.size()>0) {//Check if List is empty or not Database.update(updtaedCustomerList); System.debug('List Size '+updtaedCustomerList.size());//Update the Records } } //Finish Method global void finish(Database.BatchableContext BC){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); //Below code will fetch the job Id AsyncApexJob a = [Select a.TotalJobItems, a.Status, a.NumberOfErrors, a.JobType, a.JobItemsProcessed, a.ExtendedStatus, a.CreatedById, a.CompletedDate From AsyncApexJob a WHERE id = :BC.getJobId()];//get the job Id System.debug('$$$ Jobid is'+BC.getJobId()); //below code will send an email to User about the status mail.setToAddresses(email); mail.setReplyTo('test@test.com');//Add here your email address mail.setSenderDisplayName('Apex Batch Processing Module'); mail.setSubject('Batch Processing '+a.Status); mail.setPlainTextBody('The Batch Apex job processed '+a.TotalJobItems+'batches with '+a.NumberOfErrors+'failures'+'Job Item processed are'+a.JobItemsProcessed); Messaging.sendEmail(new Messaging.Singleemailmessage [] {mail}); } //Scheduler Method to scedule the class global void execute(SchedulableContext sc) { CustomerProessingBatch conInstance = new CustomerProessingBatch(); database.executebatch(conInstance,100); }}//Paste in Developer ConsoleCustomerProessingBatch objClass = new CustomerProessingBatch();Database.executeBatch (objClass);

上一页  [1] [2] 


Apex - 批量处理