buli
2022-04-06 2d4a8d2dcad5a17127d2c73c48ddc4b67ec79448
force-app/main/default/triggers/ContactHpDeptUpd.trigger
@@ -1,14 +1,19 @@
//医療従事者の診療科(兼務先)を変更の場合、戦略科室・病院も修正
trigger ContactHpDeptUpd on Contact (before insert, before update) {
    if((!Test.isRunningTest())&&UserInfo.getUserId()==System.Label.ByPassTrigger){
        return;
    }
    List<String> accIds = new List<String>();
    List<String> FirstNameList = new List<String>();
    List<String> LastnameList = new List<String>();
    List<String> LastnameEncryptedList = new List<String>();
    List<id> Hospital_id_list = new List<id>();
    List<id> ACCOUNT_id_list = new List<id>();
    Map<String,Contact> mapCon = new Map<String,Contact>();
//***************************************INSERT 2016-12-14 By ZDF START*************************************
//          增加“新增客户人员入例规则”
//***************************************INSERT 2016-12-14 By ZDF START*************************************
//2022-02-10    PI改造,用LastName_Encrypted__c替代原有的Name作为mapCon映射的键
    for(Contact a : Trigger.new) {
        if (Trigger.isInsert
                || (Trigger.isUpdate
@@ -21,8 +26,9 @@
        if(Trigger.isInsert&&a.Ignore_Same_Name__c==false){
            FirstNameList.add(a.firstname);
            LastnameList.add(a.Lastname);
            LastnameEncryptedList.add(a.LastName_Encrypted__c);
            ACCOUNT_id_list.add(a.Accountid);
            mapCon.put((a.firstname+a.Lastname),a);
            mapCon.put(a.LastName_Encrypted__c,a);
            system.debug('========1111111');
        }
@@ -59,9 +65,10 @@
                                        from 
                                                Contact 
                                        where   
                                                firstname  in:FirstNameList
                                        and
                                                Lastname   in:LastnameList
                                        //         firstname  in:FirstNameList
                                        // and
                                        //         Lastname   in:LastnameList
                                        LastName_Encrypted__c in : LastnameEncryptedList
                                        and     
                                            (   
                                                Account.Parent.Parentid  in:Hospital_id_list
@@ -73,22 +80,25 @@
                                ];
        system.debug('========1212121212'+FirstNameList);
        system.debug('========1212121212'+LastnameList);
        system.debug('========1212121212'+LastnameEncryptedList);
        system.debug('========1212121212'+Hospital_id_list);
        if(CntingList.size()>0){
            system.debug('========2222222'+CntingList.size());
            Contact Cnting = CntingList[0];
            for(Contact a : Trigger.new) {
                system.debug('========3333333');
                if(mapCon.containsKey(a.firstname+a.Lastname)){
                system.debug('========333333');
                if( Cnting.Account.Parent.Parent.Name   !=  null    ){
                        a.addError('该客户人员名字已存在,在'+Cnting.Account.Parent.Parent.Name+'医院下属 '+Cnting.Account.Parent.Name+'战略科室的 '+Cnting.Account.Name+'科室,请修改,或者勾选“不是重复的客户名”后,再次点击保存');
                    }   else if (   Cnting.Account.Parent.Name  !=null  ){
                        a.addError('该客户人员名字已存在,在'+Cnting.Account.Parent.Name+'医院的 '+Cnting.Account.Name+' 战略科室下,请修改,或者勾选“不是重复的客户名”后,再次点击保存');
                    }   else if (   Cnting.Account.Name !=  null    ){
                        a.addError('该客户人员名字已存在,在'+Cnting.Account.Name+'医院,请修改,或者勾选“不是重复的客户名”后,再次点击保存');
                if(mapCon.containsKey(a.LastName_Encrypted__c)){
                    //For PIPL testing by Li Jun 20220308 Start
                    // system.debug('========333333');
                    // if( Cnting.Account.Parent.Parent.Name   !=  null    ){
                    //         a.addError('该客户人员名字已存在,在'+Cnting.Account.Parent.Parent.Name+'医院下属 '+Cnting.Account.Parent.Name+'战略科室的 '+Cnting.Account.Name+'科室,请修改,或者勾选“不是重复的客户名”后,再次点击保存');
                    //     }   else if (   Cnting.Account.Parent.Name  !=null  ){
                    //         a.addError('该客户人员名字已存在,在'+Cnting.Account.Parent.Name+'医院的 '+Cnting.Account.Name+' 战略科室下,请修改,或者勾选“不是重复的客户名”后,再次点击保存');
                    //     }   else if (   Cnting.Account.Name !=  null    ){
                    //         a.addError('该客户人员名字已存在,在'+Cnting.Account.Name+'医院,请修改,或者勾选“不是重复的客户名”后,再次点击保存');
                    //     }
                    //For PIPL testing by Li Jun 20220308 End
                    }
                }
            }   
        }
    }