Asynchronous Apex 03
🎯 Challenge
LeadProcessorTest.apex
@isTest
public class LeadProcessorTest {
@isTest
public static void testit() {
List<Lead> leads = new List<Lead>();
// insert 200 Lead records
for (Integer i=0;i<200;i++) {
Lead l = new Lead();
l.LastName = 'name' + i;
l.Company = 'Company';
l.Status = 'Random Status';
leads.add(l);
}
insert leads;
//이 사이에서 해야한다
Test.startTest();
LeadProcessor lp = new LeadProcessor();
Id batchId = Database.executeBatch(lp);
Test.stopTest();
}
}
LeadProcessor.apex
global class LeadProcessor implements Database.Batchable<sObject>{
//stateful은 필요없으니 삭제
Integer count = 0;
//start
global Database.QueryLocator start(Database.BatchableContext bc) {
//collect all Lead update
return Database.getQueryLocator('SELECT ID, LeadSource FROM Lead');
}
global void execute(Database.BatchableContext bc, List<Lead> scope){
LIST<Lead> leads = new LIST<Lead>();
for (Lead lead : scope) {
lead.LeadSource = 'Dreamforce';
leads.add(lead);
count += 1;
}
update leads;
}
global void finish(Database.BatchableContext bc){
System.debug('count = ' + count);
}
}
Author And Source
이 문제에 관하여(Asynchronous Apex 03), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@wogus0808/Asynchronous-Apex-03-2i8yo73t저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)