binxie
2023-06-26 6e4766bc135c30fa9e02a2b527dcdf8fd5eeec8d
force-app/main/default/triggers/ChangedDepartmentOwner.trigger
@@ -123,17 +123,47 @@
                  AND owner_not_automatically_update__c = FALSE
        ];
        //System.debug('updateList : ' + updateList.size());
        //20220929 you SWAG-CJP7TL start 同步修改中标,失单任务所有人
        Map<Id,String> mapoppid = new Map<Id,String>();
        list<task__c> taskUpdateList = new list<task__c>();
        //20220929 you SWAG-CJP7TL end
        list<Opportunity> opUpdateList = new list<Opportunity>();
        for (Opportunity op : updateList) {
            if(op.OwnerId != acMap.get(op.AccountId)){
                op.OwnerId = acMap.get(op.AccountId);
                opUpdateList.add(op);
                //20220929 you SWAG-CJP7TL start
                mapoppid.put(op.id,acMap.get(op.AccountId));
                //20220929 you SWAG-CJP7TL end
            }
        }
        if (opUpdateList.size() > 0) {
            ControllerUtil.updOppList(opUpdateList);
        }
        //20220929 you SWAG-CJP7TL start
        if(mapoppid.size() > 0){
            List<Task__c> taskList = [
                    SELECT Id,OpportunityId__c,taskStatus__c
                    FROM task__c
                    WHERE OpportunityId__c in :mapoppid.keySet()
                    AND (RecordType.Name = '中标结果确认' OR RecordType.Name = '失单报告任务')
                    AND taskStatus__c = '02 接受'];
            system.debug(mapoppid.keySet()+'test1-----'+taskList);
            for(Task__c t: taskList){
                if(mapoppid.containsKey(t.OpportunityId__c)){
                   t.Ownerid = mapoppid.get(t.OpportunityId__c);
                   t.assignee__c = mapoppid.get(t.OpportunityId__c);
                   taskUpdateList.add(t);
                }
            }
             if (taskUpdateList != null && taskUpdateList.size() > 0) {
                update taskUpdateList;
            }
        }
        //20220929 you SWAG-CJP7TL end
    }
    // HWAG-BG682M end
}