trigger UserBefore on User (before insert, before update, after insert, after update) { Map userMap = new Map(); List userIdUpList = new List(); Map userIdUpMap = new Map(); List userIdInsList = new List(); List uIds = new List(); //zhaohui 2020-08-18 if (Trigger.isBefore) { for(User usr : Trigger.new) { //获取需要更新联盟ID的用户 if(Trigger.isUpdate && usr.IsActive == true && usr.Test_staff__c == false && usr.Employee_No__c <> null && usr.FederationIdentifier == null){ userIdUpList.add(usr.Id); } // Alias__c usr.Alias__c = usr.LastName + usr.FirstName; // Phote__c if (Trigger.isInsert && String.isBlank(usr.Photo__c) == false || (Trigger.isUpdate && ((User) Trigger.oldMap.get(usr.Id)).Photo__c != usr.Photo__c) || (Trigger.isUpdate && String.isBlank(usr.Photo__c) == false && String.isBlank(usr.Photo_Text__c)) ) { String phtTxt = ''; System.debug('UserBefore Photo__c=' + usr.Photo__c); if (String.isBlank(usr.Photo__c) == false) { Integer pStt = usr.Photo__c.indexOf('= 0) { pStt = usr.Photo__c.indexOf('src="'); if (pStt >= 0) { Integer pEnd = usr.Photo__c.indexOf('"', pStt + 5); if (pEnd >= 0) { phtTxt = usr.Photo__c.substring(pStt + 5, pEnd); System.debug('UserBefore phpTxt1=' + phtTxt); phtTxt = phtTxt.unescapeHtml4(); System.debug('UserBefore phpTxt2=' + phtTxt); } } } } usr.Photo_Text__c = phtTxt; } } if(userIdUpList.size() > 0){ List updateList = [ select id,Name,Employee_No__c,FederationIdentifier from user where id in :userIdUpList and Profile.UserLicense.Name= 'salesforce']; for (user us : updateList) { userIdUpMap.put(us.Id,us); } for(User usr : Trigger.new) { if(userIdUpMap.containsKey(usr.Id)){ usr.FederationIdentifier = usr.Employee_No__c + '@olympus.com.cn'; } } } } // CIC 130175 start else { // Trigger.isAfter for(User usr : Trigger.new) { // MB関連 if (Trigger.isInsert && String.isBlank(usr.Province__c) == false || (Trigger.isUpdate && (Trigger.oldMap.get(usr.Id)).Province__c != usr.Province__c) ) { userMap.put(usr.Id, usr); } ////获取需要更新联盟ID的用户 if (Trigger.isInsert && usr.IsActive == true && usr.Test_staff__c == false && usr.Employee_No__c <> null && usr.FederationIdentifier == null){ userIdInsList.add(usr.Id); } //zhaohui 2020-08-18 start if (Trigger.isUpdate && !usr.IsActive && (Trigger.oldMap.get(usr.Id)).IsActive != usr.IsActive) { uIds.add(usr.Id); } //zhaohui 2020-08-18 end } // MBこどもを更新 //ControllerUtil.updMBChildFromUser(userMap); if(userIdInsList.size() > 0){ List updateList = [ select id,Name,Employee_No__c,FederationIdentifier from user where IsActive = true and Test_staff__c = false and Employee_No__c <> null and id in :userIdInsList and Profile.UserLicense.Name= 'salesforce']; for (user us : updateList) { us.FederationIdentifier = us.Employee_No__c + '@olympus.com.cn'; //userIdInsMap.put(us.Id,us); } ControllerUtil.upUserFederationIdentifier(updateList); } //zhaohui 2020-08-18 start if (uIds.size() > 0) { Database.executeBatch(new CloseTaskUpdateBatch(uIds)); } //zhaohui 2020-08-18 end } // CIC 130175 end }