高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
/**
 * Class名: AgencyShareUpdateBatch
 * 理由: 现在只有 Agency_Opportunity__c, 以后会有扩展的可能
 */
global class AgencyShareUpdateBatch implements Database.Batchable<sObject> {
 
    global AgencyShareUpdateBatch() {
    }
 
    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator([SELECT Id
                , OCSM_Owner__c
                , Department_Class_Opp__c
                , Department_Class_Opp__r.OwnerId
             FROM Agency_Opportunity__c
            WHERE NeedShareBatch__c = true
        ]);
    }
 
    global void execute(Database.BatchableContext bc, List<Agency_Opportunity__c> scope) {
        List<Agency_Opportunity__c> updList = new List<Agency_Opportunity__c>();
        for (Agency_Opportunity__c nObj : scope) {
            if (nObj.Department_Class_Opp__c != null
                    && nObj.OCSM_Owner__c != nObj.Department_Class_Opp__r.OwnerId) {
                nObj.OCSM_Owner__c = nObj.Department_Class_Opp__r.OwnerId;
            }
            updList.add(nObj);
        }
        update updList;
    }
 
    global void finish(Database.BatchableContext bc) {
        Id execBTId = Database.executebatch(new NFM603Batch(),1);
    }
}