public without sharing class ContactTriggerHandler { public static void setIsNew(List newList, Map newMap, List oldList, Map oldMap) { for (Contact newCon : newList) { // String new_profileId = UserInfo.getProfileId().subString(0,15); //calendarUtil.getMemberProfileID 这里用到的人员ID 和获取到的简档ID都是15位的 String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15)); if (new_profileId.subString(0,15) == System.label.Market_Department || new_profileId.subString(0,15) == System.label.Market_Department1 || new_profileId.subString(0,15) == System.label.Service_Owner || UserInfo.getUserType() == 'PowerPartner') { newCon.IsNew__c = true; } else { newCon.MobilePhoneD__c = newCon.MobilePhone; newCon.OtherPhoneD__c = newCon.OtherPhone; newCon.FaxD__c = newCon.Fax; newCon.EmailD__c = newCon.Email; newCon.PhoneD__c = newCon.Phone; newCon.TitleD__c = newCon.Title; newCon.Address1D__c = newCon.Address1__c; newCon.Address2D__c = newCon.Address2__c; newCon.Address3D__c = newCon.Address3__c; newCon.PostcodeD__c = newCon.Postcode__c; newCon.ContactStatusD__c = newCon.ContactStatus__c; newCon.CancelReasonD__c = newCon.CancelReason__c; if(new_profileId.subString(0,15) == '00e28000000YKLo'){ newCon.IsNew__c = true; } // PIPL Update 20220420 By Chen Yanan Start newCon.MobilePhoneD_Encrypted__c = newCon.MobilePhone_Encrypted__c; newCon.OtherPhoneD_Encrypted__c = newCon.OtherPhone_Encrypted__c; newCon.FaxD_Encrypted__c = newCon.Fax_Encrypted__c; newCon.EmailD_Encrypted__c = newCon.Email_Encrypted__c; newCon.PhoneD_Encrypted__c = newCon.Phone_Encrypted__c; newCon.TitleD_Encrypted__c = newCon.Title_Encrypted__c; newCon.Address1D_Encrypted__c = newCon.Address1_Encrypted__c; newCon.Address2D_Encrypted__c = newCon.Address2_Encrypted__c; newCon.Address3D_Encrypted__c = newCon.Address3_Encrypted__c; newCon.PostcodeD_Encrypted__c = newCon.Postcode_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } System.debug('setIsNew newCon: ' + newCon); } } public static void updateForDealer(List newList, Map newMap, List oldList, Map oldMap) { //王鹏伟 添加userId 服务部修改联系人重新审批 判断当前修改的登陆人是否是孙学洋 吴晓东 String userId = UserInfo.getUserId(); for (Contact newCon : newList) { Contact oldCon = oldMap.get(newCon.Id); if(newCon.AccountStaut__c != 'Pass' && newCon.StatusD__c != oldCon.StatusD__c && newCon.StatusD__c == 'Pass' ){ newCon.addError('请先审批对应的客户'); } if (newCon.MobilePhoneD__c != oldCon.MobilePhoneD__c || newCon.OtherPhoneD__c != oldCon.OtherPhoneD__c || newCon.FaxD__c != oldCon.FaxD__c || newCon.EmailD__c != oldCon.EmailD__c || newCon.PhoneD__c != oldCon.PhoneD__c || newCon.TitleD__c != oldCon.TitleD__c || newCon.Address1D__c != oldCon.Address1D__c || newCon.Address2D__c != oldCon.Address2D__c || newCon.Address3D__c != oldCon.Address3D__c || newCon.PostcodeD__c != oldCon.PostcodeD__c || newCon.ContactStatusD__c != oldCon.ContactStatusD__c || newCon.CancelReasonD__c != oldCon.CancelReasonD__c) { // String new_profileId = UserInfo.getProfileId().subString(0,15); //新的获取简档ID calendarUtil.getMemberProfileID 这里用到的人员ID 和获取到的简档ID都是15位的 String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15)); //王鹏伟 添加 && !((oldCon.ProductSegment__c == 'BS' || oldCon.ProductSegment__c == 'NDT' || oldCon.ProductSegment__c = 'ANI') && oldCon.isServiceCreate__c == true) //服务部修改联系人信息 LS、NDT、ANI无需审批,跳过审批状态变草案 if (( new_profileId.subString(0,15) == System.label.Service_Owner || UserInfo.getUserType() == 'PowerPartner' || userId =='00528000000YWC6' || userId =='00528000000YWE7') && !((oldCon.ProductSegment__c == 'BS' || oldCon.ProductSegment__c == 'NDT' || oldCon.ProductSegment__c == 'ANI') && oldCon.isServiceCreate__c == true)) { newCon.StatusD__c = 'Draft'; } } if (newCon.MobilePhone != oldCon.MobilePhone) { newCon.MobilePhoneD__c = newCon.MobilePhone; // PIPL Update 20220420 By Chen Yanan Start System.debug('MobilePhoneD_Encrypted__c'); newCon.MobilePhoneD_Encrypted__c = newCon.MobilePhone_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } if (newCon.OtherPhone != oldCon.OtherPhone) { newCon.OtherPhoneD__c = newCon.OtherPhone; // PIPL Update 20220420 By Chen Yanan Start System.debug('OtherPhoneD_Encrypted__c'); newCon.OtherPhoneD_Encrypted__c = newCon.OtherPhone_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } if (newCon.Fax != oldCon.Fax) { newCon.FaxD__c = newCon.Fax; // PIPL Update 20220420 By Chen Yanan Start System.debug('FaxD_Encrypted__c'); newCon.FaxD_Encrypted__c = newCon.Fax_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } if (newCon.Email != oldCon.Email) { newCon.EmailD__c = newCon.Email; // PIPL Update 20220420 By Chen Yanan Start System.debug('EmailD_Encrypted__c'); newCon.EmailD_Encrypted__c = newCon.Email_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } if (newCon.Phone != oldCon.Phone) { newCon.PhoneD__c = newCon.Phone; // PIPL Update 20220420 By Chen Yanan Start System.debug('PhoneD_Encrypted__c'); newCon.PhoneD_Encrypted__c = newCon.Phone_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } if (newCon.Title != oldCon.Title) { newCon.TitleD__c = newCon.Title; // PIPL Update 20220420 By Chen Yanan Start System.debug('TitleD_Encrypted__c'); newCon.TitleD_Encrypted__c = newCon.Title_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } if (newCon.Address1__c != oldCon.Address1__c) { newCon.Address1D__c = newCon.Address1__c; System.debug('Address1D_Encrypted__c'); // PIPL Update 20220420 By Chen Yanan Start newCon.Address1D_Encrypted__c = newCon.Address1_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } if (newCon.Address2__c != oldCon.Address2__c) { newCon.Address2D__c = newCon.Address2__c; System.debug('Address2D_Encrypted__c'); // PIPL Update 20220420 By Chen Yanan Start newCon.Address2D_Encrypted__c = newCon.Address2_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } if (newCon.Address3__c != oldCon.Address3__c) { newCon.Address3D__c = newCon.Address3__c; System.debug('Address3D_Encrypted__c'); // PIPL Update 20220420 By Chen Yanan Start newCon.Address3D_Encrypted__c = newCon.Address3_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } if (newCon.Postcode__c != oldCon.Postcode__c) { newCon.PostcodeD__c = newCon.Postcode__c; System.debug('PostcodeD_Encrypted__c'); // PIPL Update 20220420 By Chen Yanan Start newCon.PostcodeD_Encrypted__c = newCon.Postcode_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } if (newCon.ContactStatus__c != oldCon.ContactStatus__c) { newCon.ContactStatusD__c = newCon.ContactStatus__c; } if (newCon.CancelReason__c != oldCon.CancelReason__c) { newCon.CancelReasonD__c = newCon.CancelReason__c; } System.debug('updateForDealer newCon: ' + newCon); } } public static void dealerContactApproval(List newList, Map newMap, List oldList, Map oldMap) { List accIdList = new List(); for (Contact newCon : newList) { accIdList.add(newCon.AccountId); } // 现有客户小组 Map accsMap = new Map(); //List atmList = [select Id, AccountId, UserId from AccountTeamMember where AccountId in :accIdList]; List accsList = [select id, accountId, UserOrGroupId, AccountAccessLevel, RowCause from AccountShare where AccountId in :accIdList and RowCause = 'Team']; for (AccountShare accs : accsList) { accsMap.put(accs.AccountId + '' + accs.UserOrGroupId, accs.Id); } // 需要更新客户小组 // List updList = new List(); //新的获取简档ID calendarUtil.getMemberProfileID 这里用到的人员ID 和获取到的简档ID都是15位的 // String new_profileId = UserInfo.getProfileId().subString(0,15); String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15)); for (Contact newCon : newList) { Contact oldCon = oldMap.get(newCon.Id); if (new_profileId.subString(0,15) == System.label.Market_Department || new_profileId.subString(0,15) == System.label.Market_Department1){ newCon.MobilePhone = newCon.MobilePhoneD__c; newCon.OtherPhone = newCon.OtherPhoneD__c; newCon.Fax = newCon.FaxD__c; newCon.Email = newCon.EmailD__c; newCon.Phone = newCon.PhoneD__c; newCon.Title = newCon.TitleD__c; newCon.Address1__c = newCon.Address1D__c; newCon.Address2__c = newCon.Address2D__c; newCon.Address3__c = newCon.Address3D__c; newCon.Postcode__c = newCon.PostcodeD__c; newCon.ContactStatus__c = newCon.ContactStatusD__c; newCon.CancelReason__c = newCon.CancelReasonD__c; // PIPL Update 20220420 By Chen Yanan Start newCon.MobilePhone_Encrypted__c = newCon.MobilePhoneD_Encrypted__c; newCon.OtherPhone_Encrypted__c = newCon.OtherPhoneD_Encrypted__c; newCon.Fax_Encrypted__c = newCon.FaxD_Encrypted__c; newCon.Email_Encrypted__c = newCon.EmailD_Encrypted__c; newCon.Phone_Encrypted__c = newCon.PhoneD_Encrypted__c; newCon.Title_Encrypted__c = newCon.TitleD_Encrypted__c; newCon.Address1_Encrypted__c = newCon.Address1D_Encrypted__c; newCon.Address2_Encrypted__c = newCon.Address2D_Encrypted__c; newCon.Address3_Encrypted__c = newCon.Address3D_Encrypted__c; newCon.Postcode_Encrypted__c = newCon.PostcodeD_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } else if (newCon.StatusD__c != oldCon.StatusD__c) { if (newCon.StatusD__c == 'Submit') { //newCon.DealerSelectOwner__c = newCon.Account.DealerSelectOwner__c; } if (newCon.StatusD__c == 'Pass') { // 批准过程肯定是一条一条批准的,所以这里再循环中写了select文 List accList = [select Id, IsNew__c, AccountStatus__c from Account where Id = :newCon.AccountId]; if (accList.size() > 0 ) { Account acc = accList[0]; if (acc.IsNew__c == true || (acc.AccountStatus__c == 'Cancel' && newCon.ContactStatusD__c != 'Cancel')) { newCon.addError('客户无效或未通过审批,不能批准当前联系人。'); } } newCon.MobilePhone = newCon.MobilePhoneD__c; newCon.OtherPhone = newCon.OtherPhoneD__c; newCon.Fax = newCon.FaxD__c; newCon.Email = newCon.EmailD__c; newCon.Phone = newCon.PhoneD__c; newCon.Title = newCon.TitleD__c; newCon.Address1__c = newCon.Address1D__c; newCon.Address2__c = newCon.Address2D__c; newCon.Address3__c = newCon.Address3D__c; newCon.Postcode__c = newCon.PostcodeD__c; newCon.ContactStatus__c = newCon.ContactStatusD__c; newCon.CancelReason__c = newCon.CancelReasonD__c; // PIPL Update 20220420 By Chen Yanan Start System.debug('Pass'); newCon.MobilePhone_Encrypted__c = newCon.MobilePhoneD_Encrypted__c; newCon.OtherPhone_Encrypted__c = newCon.OtherPhoneD_Encrypted__c; newCon.Fax_Encrypted__c = newCon.FaxD_Encrypted__c; newCon.Email_Encrypted__c = newCon.EmailD_Encrypted__c; newCon.Phone_Encrypted__c = newCon.PhoneD_Encrypted__c; newCon.Title_Encrypted__c = newCon.TitleD_Encrypted__c; newCon.Address1_Encrypted__c = newCon.Address1D_Encrypted__c; newCon.Address2_Encrypted__c = newCon.Address2D_Encrypted__c; newCon.Address3_Encrypted__c = newCon.Address3D_Encrypted__c; newCon.Postcode_Encrypted__c = newCon.PostcodeD_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End // if (accsMap.containsKey(newCon.AccountId + '' + newCon.OwnerId) == true && newCon.IsNew__c == true) { // AccountShare upd = new AccountShare( // Id = accsMap.get(newCon.AccountId + '' + newCon.OwnerId), // AccountAccessLevel = 'Edit' // ); // updList.add(upd); // } if (newCon.IsNew__c = true) { newCon.IsNew__c = false; } } if (newCon.StatusD__c == 'Reject' && newCon.IsNew__c == false) { newCon.MobilePhoneD__c = newCon.MobilePhone; newCon.OtherPhoneD__c = newCon.OtherPhone; newCon.FaxD__c = newCon.Fax; newCon.EmailD__c = newCon.Email; newCon.PhoneD__c = newCon.Phone; newCon.TitleD__c = newCon.Title; newCon.Address1D__c = newCon.Address1__c; newCon.Address2D__c = newCon.Address2__c; newCon.Address3D__c = newCon.Address3__c; newCon.PostcodeD__c = newCon.Postcode__c; newCon.ContactStatusD__c = newCon.ContactStatus__c; newCon.CancelReasonD__c = newCon.CancelReason__c; // PIPL Update 20220420 By Chen Yanan Start System.debug('Reject'); newCon.MobilePhoneD_Encrypted__c = newCon.MobilePhone_Encrypted__c; newCon.OtherPhoneD_Encrypted__c = newCon.OtherPhone_Encrypted__c; newCon.FaxD_Encrypted__c = newCon.Fax_Encrypted__c; newCon.EmailD_Encrypted__c = newCon.Email_Encrypted__c; newCon.PhoneD_Encrypted__c = newCon.Phone_Encrypted__c; newCon.TitleD_Encrypted__c = newCon.Title_Encrypted__c; newCon.Address1D_Encrypted__c = newCon.Address1_Encrypted__c; newCon.Address2D_Encrypted__c = newCon.Address2_Encrypted__c; newCon.Address3D_Encrypted__c = newCon.Address3_Encrypted__c; newCon.PostcodeD_Encrypted__c = newCon.Postcode_Encrypted__c; // PIPL Update 20220420 By Chen Yanan End } System.debug('dealerContactApproval newCon: ' + newCon); } } // 更新客户小组 // if (updList!= null && updList.size() > 0) { // update updList; // } } }