forest_moon
Apex Lead Batch + Schedulable 본문
Batch 에 Schedule 를 추가 했다.
Schedulable 인터페이스를 추가하고 , batch class 를 호출할 수있게 excute를 추가 함.
global class LeadStatusBatch implements Database.Batchable<sObject>, Database.stateful, Schedulable {
// 추가한부분
global void execute(SchedulableContext sc){
System.debug('☆★☆★☆★☆★☆★ execute');
LeadStatusBatch b = new LeadStatusBatch();
Database.executeBatch(b,200);
}
global Database.QueryLocator start(Database.BatchableContext BC) {
System.debug(':::: Batch Start::::');
String query = 'SELECT ';
query += 'Id, ';
query += 'Status, ';
query += 'CreatedDate ';
query += 'FROM Lead ';
query += 'WHERE (Status = \'신규\' OR Status = \'수요검색 \') ';
query += 'AND CreatedDate < LAST_N_DAYS: 90';
System.debug(query);
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc, List<Lead> scope) {
System.debug(':::: Batch execute ::::');
System.debug('scope is' + scope );
List<Lead> leadList = new List<Lead>();
try {
if(scope.size() > 0){
for(Lead ld : scope){
ld.Status = '수요없음';
leadList.add(ld);
}
update leadList;
}
} catch (Exception e) {
System.debug('exception : '+ e );
}
}
global void finish(Database.BatchableContext BC) {
System.debug(':::: Batch Finish::::');
}
}
Salesforce Standard Out of Box Schedule (세일즈포스에서 스케쥴 등록 하기)
**필수사항
- class 에 인터페이스 Schedulable 을 구현 해야 함.
implements Schedulable
2. batch class 내에 메서드를 추가 해줘야 Schedule을 통해서 Batch를 동작 시킴
global void execute(SchedulableContext sc){
System.debug('☆★☆★☆★☆★☆★ execute');
LeadStatusBatch b = new LeadStatusBatch();
Database.executeBatch(b,200);
}
1. 스케쥴러를 등록하는 방법은 Setup >> Home >> apex 검색 >> Apex Classes >>Schedule Apex 클릭
위 화면에서 Apex Class를 등록하고 스케쥴 실행하는 날짜와 시간 요일을 지정 할 수 있다.( 1시간 이내는 불가능)
// 크론표기법 사용하면 가능
**** Schedule Apex 를 한번 설정하면 수정 불가능 삭제만 가능하다
2. 등록한 Schedule 확인하기
Setup >> Enviroments >> Jobs >> Scheduled Jobs 에서 확인 가능
지정된 시간이 되면
3. Batch class 실행 확인하기
해당 시간전에 Develop console에 들어가서 지정된 시간이 되면 실행이 될것이고 log 를 확인
'Saelsforcee' 카테고리의 다른 글
세일즈포스 월드투어 후기 (0) | 2024.06.21 |
---|---|
Salesforce Standard label 변경 (0) | 2023.12.04 |
Apex Lead Batch (2) Testcode (0) | 2023.11.20 |
Apex Lead Batch (1) (0) | 2023.11.20 |
Salesforce Standard PDF Features (0) | 2023.10.24 |