GWY
2022-05-21 a3460549533111815e7f73d6cef601a58031525d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
global class ProRegisterBatch implements Database.Batchable<sObject> {
    String regId;
    
    global ProRegisterBatch(String regId) {
        this.regId = regId;
    }
 
    global ProRegisterBatch() {
        
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        Date yesterday = Date.Today() - 1;
        
        if (String.isBlank(this.regId)) {
            return Database.getQueryLocator([select id, ValidProductRegister__c
                                               from Product_Register__c 
                                              where ValidProductRegister__c = false
                                                and ValidTo__c = yesterday ]);
 
        } else {
            if (this.regId == 'updateAllInvalidData') {
                return Database.getQueryLocator([select id, ValidProductRegister__c
                                               from Product_Register__c 
                                              where ValidProductRegister__c = false ]);
                                                
            } else {
                return Database.getQueryLocator([select id, ValidProductRegister__c 
                                               from Product_Register__c 
                                              where id = :this.regId
                                                and ValidTo__c <= :Date.Today()]);    
            }
            
        }
    }
 
    global void execute(Database.BatchableContext BC, List<Product_Register__c> dcList) {
        
        if (dcList.size() > 0) update dcList;
    }
 
    global void finish(Database.BatchableContext BC) {
        
    }
}