본문 바로가기

Salesforce/Tips

세일즈포스 배치 동적 실행 (Salesforce batch dynamic execution)

728x90

Salesforce에서 작성한 Batch 실행 시 Class를 직접 선언하지 않고, Class Name의 String 값을 가지고, Type.forname()를 이용하여 동적으로 newInstance를 생성해 실행할 수 있습니다.

// 일반적인 배치 실행
SampleBatch sampleBatch = new SampleBatch();
database.executeBatch(sampleBatch, 200);

// 동적인 배치 실행
String BATCH_NAME = 'SampleBatch';
Integer BATCH_SIZE = 200;
database.executeBatch((Database.Batchable<sObject>)Type.forname(BATCH_NAME)
						.newInstance(), BATCH_SIZE);

 

728x90