public without sharing class RentalApplyShareHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; public RentalApplyShareHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } protected override void afterInsert() { addStrategiccShare(); } protected override void afterUpdate() { addStrategiccShare(); } protected override void beforeInsert() { dataCheck(); } protected override void beforeUpdate() { dataCheck(); } //add by rentx 2020-12-03 start 新建共享数据 private Rental_Apply__Share makeData(String parentId, String userId) { Rental_Apply__Share ras = new Rental_Apply__Share(); ras.RowCause = 'Manual'; ras.ParentId = parentId; ras.UserOrGroupId = userId; ras.AccessLevel = 'Edit'; return ras; } //add by rentx 2020-12-03 end 新建共享数据 private void addStrategiccShare() { //add by rentx 2020-11-16 SFDC-BVA5VJ start // List aids = new List();//20210728 ljh SFDC-C5645S start // List ratList = new List();//20210728 ljh SFDC-C5645S start // List raoList = new List();//20210728 ljh SFDC-C5645S start //add by rentx 2020-11-16 SFDC-BVA5VJ end List raList = new List(); List delStrategList = new List(); List addStrategList = new List(); //20210728 ljh SFDC-C5645S start List addStrategListL = new List(); // List ParentIdList = new List(); // List UserOrGroupIdList = new List(); // Map PUMap = new Map(); Set ParentIdSet = new Set(); Set UserOrGroupIdSet = new Set(); Set UserOrGroupIdOldSet = new Set(); Map PUMap = new Map(); Map RAUMap = new Map(); List IsActiveNoList = new List(); //20210728 ljh SFDC-C5645S end for (Rental_Apply__c nObj : newList) { if (nObj.Strategic_user__c != null && (Trigger.isInsert || (nObj.ShareFlag__c == true && Trigger.isUpdate))) { // 20210924 ljh SFDC-C758NB update substring(0,15) start // if (!nObj.Strategic_user__c.equals(nObj.OwnerId) if (!String.valueOf(nObj.Strategic_user__c).substring(0,15).equals(String.valueOf(nObj.OwnerId).substring(0,15)) && (nObj.Approver_of_Service_Department__c == null || ( nObj.Approver_of_Service_Department__c != null && !String.valueOf(nObj.Strategic_user__c).substring(0,15).equals(String.valueOf(nObj.Approver_of_Service_Department__c).substring(0,15)) ) ) ) { // 20210924 ljh SFDC-C758NB update substring(0,15) end Rental_Apply__Share ras = new Rental_Apply__Share( RowCause = 'Manual', ParentId = nObj.Id, UserOrGroupId = nObj.Strategic_user__c, AccessLevel = 'read' ); addStrategList.add(ras); } //20210728 ljh SFDC-C5645S start Rental_Apply__c ra = new Rental_Apply__c(); ra.Id = nObj.Id; ra.ShareStrategicUser__c = nObj.Strategic_user__c; raList.add(ra); //20210728 ljh SFDC-C5645S end } //判断战略科室主担当是否发生更改 if (nObj.ShareFlag__c == true && Trigger.isUpdate) { //删除原来的共享 if (String.isNotBlank(nObj.ShareStrategicUser__c)) { PUMap.put(nObj.Id, nObj); ParentIdSet.add(nObj.Id); UserOrGroupIdOldSet.add(nObj.ShareStrategicUser__c); } } //20210728 ljh SFDC-C5645S 加入共享前判断用户是否可用 start //如果 执行的Insert操作或者发生GI担当改变,设置共享\ //如果执行的是insert操作 //判断GI是否发生改变 /*if (nObj.hospitalLeaderGIchange__c == true && String.isNotBlank(nobj.Strategic_userFSEGI__c) && !nObj.OwnerId.equals(nObj.Strategic_userFSEGI__c)) { //加入共享 Rental_Apply__Share ras = makeData(nObj.Id,nObj.Strategic_userFSEGI__c); addStrategList.add(ras); //设置hospitalLeaderGI__c的值 Rental_Apply__c ra = new Rental_Apply__c(); ra.Id = nObj.Id; ra.hospitalLeaderGI__c = nObj.Strategic_userFSEGI__c; ratList.add(ra); } //判断SP是否发生改变 if (nObj.hospitalLeaderSPchange__c && String.isNotBlank(nobj.Strategic_userFSESP__c) && !nObj.OwnerId.equals(nObj.Strategic_userFSESP__c)) { //加入共享 Rental_Apply__Share ras = makeData(nObj.Id,nObj.Strategic_userFSESP__c); addStrategList.add(ras); //设置hospitalLeaderSP__c的值 Rental_Apply__c ra = new Rental_Apply__c(); ra.Id = nObj.Id; ra.hospitalLeaderSP__c = nObj.Strategic_userFSESP__c; raoList.add(ra); } //判断战略科室主担当是否和 SP/GI之前的值一样 if ((nObj.hospitalLeaderSPchange__c && String.isNotBlank(nObj.hospitalLeaderSP__c) && String.isNotBlank(nObj.Strategic_user__c) && nObj.Strategic_user__c.equals(nObj.hospitalLeaderSP__c)) || (nObj.hospitalLeaderGIchange__c && String.isNotBlank(nObj.hospitalLeaderGI__c) && String.isNotBlank(nObj.Strategic_user__c) && nObj.Strategic_user__c.equals(nObj.hospitalLeaderGI__c))) { Rental_Apply__Share ras = new Rental_Apply__Share( RowCause = 'Manual', ParentId = nObj.Id, UserOrGroupId = nObj.Strategic_user__c, AccessLevel = 'read' ); addStrategList.add(ras); } //如果是新建备品或者战略科室分类发生改变 if (Trigger.isInsert || (Trigger.isUpdate && nObj.OCM_dept_category__c != oldMap.get(nObj.Id).OCM_dept_category__c) ) { //判断新的战略科室是什么 String dept = nObj.OCM_dept_category__c; if(string.isNotBlank(dept)){ if ((nObj.Job_Category__c =='销售服务') && (dept.equals('消化科') ||dept.equals('呼吸科') || dept.equals('ET') || dept.equals('其他')) && String.isNotBlank(nobj.Strategic_userFSEGI__c) && !nObj.OwnerId.equals(nObj.Strategic_userFSEGI__c)) { //加入共享 Rental_Apply__Share ras = makeData(nObj.Id,nObj.Strategic_userFSEGI__c); addStrategList.add(ras); } if ((nObj.Job_Category__c =='销售服务') && (dept.equals('普外科') ||dept.equals('泌尿科') || dept.equals('妇科') || dept.equals('耳鼻喉科') || dept.equals('其他')) && String.isNotBlank(nobj.Strategic_userFSESP__c) && !nObj.OwnerId.equals(nObj.Strategic_userFSESP__c)) { //加入共享 Rental_Apply__Share ras = makeData(nObj.Id,nObj.Strategic_userFSESP__c); addStrategList.add(ras); } } } //判断现在执行的操作是否为 更新 if (Trigger.isUpdate) { //换换姐的 //删除原来的共享 --战略科室主担当 if(nObj.ShareFlag__c==true &&String.isNotBlank(nObj.ShareStrategicUser__c)){ PUMap.put(nObj.Id,nObj.ShareStrategicUser__c); ParentIdList.add(nObj.Id); UserOrGroupIdList.add(nObj.ShareStrategicUser__c); } //如果战略科室发生改变 if (nObj.OCM_dept_category__c != oldMap.get(nObj.Id).OCM_dept_category__c) { if (String.isNotBlank(nobj.hospitalLeaderGI__c)) { PUMap.put(nObj.Id,nObj.hospitalLeaderGI__c); UserOrGroupIdList.add(nObj.hospitalLeaderGI__c); } if (String.isNotBlank(nObj.hospitalLeaderSP__c)) { PUMap.put(nObj.Id,nObj.hospitalLeaderSP__c); UserOrGroupIdList.add(nObj.hospitalLeaderSP__c); } ParentIdList.add(nObj.Id); } //战略科室FSEGI担当,如果发生改变 if (nObj.hospitalLeaderGIchange__c == true && String.isNotBlank(nObj.hospitalLeaderGI__c)) { PUMap.put(nObj.Id,nObj.hospitalLeaderGI__c); ParentIdList.add(nObj.Id); UserOrGroupIdList.add(nObj.hospitalLeaderGI__c); } //战略科室FSESP担当,如果发生改变 if (nObj.hospitalLeaderSPchange__c == true && String.isNotBlank(nObj.hospitalLeaderSP__c)) { PUMap.put(nObj.Id,nObj.hospitalLeaderSP__c); ParentIdList.add(nObj.Id); UserOrGroupIdList.add(nObj.hospitalLeaderSP__c); } //判断战略科室主担当是否和 SP/GI之前的值一样 if ((nObj.hospitalLeaderSPchange__c && String.isNotBlank(nObj.hospitalLeaderSP__c) && String.isNotBlank(nObj.Strategic_user__c) && nObj.Strategic_user__c.equals(nObj.hospitalLeaderSP__c)) || (nObj.hospitalLeaderGIchange__c && String.isNotBlank(nObj.hospitalLeaderGI__c) && String.isNotBlank(nObj.Strategic_user__c) && nObj.Strategic_user__c.equals(nObj.hospitalLeaderGI__c))) { PUMap.put(nObj.Id,nObj.Strategic_user__c); ParentIdList.add(nObj.Id); UserOrGroupIdList.add(nObj.Strategic_user__c); } }20210728 ljh SFDC-C5645S 注释*/ // System.debug('zheli00:'+nObj.OwnerId.equals(nObj.Strategic_userFSEGI__c)+'~'+nObj.Strategic_userFSEGI__c+'~'+nObj.OwnerId); // System.debug('zheli11:'+nObj.OwnerId.equals(nObj.Strategic_userFSESP__c)+'~'+nObj.Strategic_userFSESP__c+'~'+nObj.OwnerId+'||'+nObj.hospitalLeaderGIchange__c+'~'+nObj.hospitalLeaderSPchange__c); // System.debug('zheli22:'+nObj.hospitalLeaderGIchange__c+'~'+nObj.hospitalLeaderSPchange__c); // 20210924 ljh SFDC-C758NB update substring(0,15) start // if ( // (nObj.hospitalLeaderGIchange__c && String.isNotBlank(nobj.Strategic_userFSEGI__c) && !nObj.OwnerId.equals(nObj.Strategic_userFSEGI__c)) // || (nObj.hospitalLeaderSPchange__c && String.isNotBlank(nobj.Strategic_userFSESP__c) && !nObj.OwnerId.equals(nObj.Strategic_userFSESP__c)) // ) { if ( (nObj.hospitalLeaderGIchange__c && String.isNotBlank(nobj.Strategic_userFSEGI__c) && !String.valueOf(nObj.OwnerId).substring(0,15).equals(String.valueOf(nObj.Strategic_userFSEGI__c).substring(0,15))) || (nObj.hospitalLeaderSPchange__c && String.isNotBlank(nobj.Strategic_userFSESP__c) && !String.valueOf(nObj.OwnerId).substring(0,15).equals(String.valueOf(nObj.Strategic_userFSESP__c).substring(0,15))) ) { // if (nObj.hospitalLeaderGIchange__c) { if (nObj.hospitalLeaderGIchange__c && !String.valueOf(nObj.OwnerId).substring(0,15).equals(String.valueOf(nObj.Strategic_userFSEGI__c).substring(0,15))) { Rental_Apply__Share ras = makeData(nObj.Id, nObj.Strategic_userFSEGI__c); PUMap.put(nObj.Id, nObj); ParentIdSet.add(nObj.Id); UserOrGroupIdSet.add(nObj.Strategic_userFSEGI__c); UserOrGroupIdOldSet.add(nObj.hospitalLeaderGI__c); addStrategListL.add(ras); } // if (nObj.hospitalLeaderSPchange__c) { if (nObj.hospitalLeaderSPchange__c && !String.valueOf(nObj.OwnerId).substring(0,15).equals(String.valueOf(nObj.Strategic_userFSESP__c).substring(0,15))) { Rental_Apply__Share ras = makeData(nObj.Id, nObj.Strategic_userFSESP__c); PUMap.put(nObj.Id, nObj); ParentIdSet.add(nObj.Id); UserOrGroupIdSet.add(nObj.Strategic_userFSESP__c); UserOrGroupIdOldSet.add(nObj.hospitalLeaderSP__c); addStrategListL.add(ras); } } //20210728 ljh SFDC-C5645S 加入共享前判断用户是否可用 end } // 20210924 ljh SFDC-C758NB update substring(0,15) end if(UserOrGroupIdSet.size() > 0){ for (User user : [Select Id, Name, IsActive From User WHERE Id in:UserOrGroupIdSet]) { //未启用 if (!user.IsActive) { String userId = (String)user.Id; userId = userId.substring(0, 15); IsActiveNoList.add(userId); } } } //add by rentx 2020-11-26 SFDC-BVA5VJ end // System.debug('zheli22:'+UserOrGroupIdOldSet.size()+'~'+ParentIdSet.size()); if(UserOrGroupIdOldSet.size() > 0 && ParentIdSet.size() > 0 ){ //删除原来的共享 delStrategList = [SELECT Id, ParentId, UserOrGroupId FROM Rental_Apply__Share WHERE RowCause = 'Manual' AND ParentId in :ParentIdSet AND UserOrGroupId in :UserOrGroupIdOldSet]; for (Integer m = 0; m < delStrategList.size(); m++) { if (PUMap.get(delStrategList[m].ParentId) == null) { delStrategList.remove(m); } } if (delStrategList.size() > 0) { // System.debug('zheli11:'+delStrategList); delete delStrategList; } } //增加 if (addStrategListL.size() > 0) { //20210728 ljh SFDC-C5645S for (Rental_Apply__Share ras : addStrategListL) { String temp = (String)ras.UserOrGroupId; if ( IsActiveNoList.size() == 0 || (IsActiveNoList.size() > 0 && !IsActiveNoList.contains(temp.substring(0, 15))) ) { addStrategList.add(ras); } Rental_Apply__c Ra = PUMap.get(ras.ParentId); Rental_Apply__c raU = new Rental_Apply__c(); if (Ra != null ) { // System.debug('zheli00:'+Ra.hospitalLeaderGIchange__c+'~'+Ra.hospitalLeaderSPchange__c); raU.Id = Ra.Id; String tempGI = Ra.Strategic_userFSEGI__c; String tempSP = Ra.Strategic_userFSESP__c; if (Ra.hospitalLeaderGIchange__c && String.isNotBlank(tempGI)) { raU.hospitalLeaderGI__c = Ra.Strategic_userFSEGI__c; } else { raU.hospitalLeaderGI__c = ''; } if (Ra.hospitalLeaderSPchange__c && String.isNotBlank(tempSP)) { raU.hospitalLeaderSP__c = Ra.Strategic_userFSESP__c; } else { raU.hospitalLeaderSP__c = ''; } RAUMap.put(raU.Id, raU); } } //20210728 ljh SFDC-C5645S end } // System.debug('zheli00:'+addStrategList); // 共享表 if (addStrategList.size() > 0) { insert addStrategList; } // 更新 // 20210924 ljh SFDC-C758NB update 优化 start if (raList.size() > 0) { // update raList; for(Rental_Apply__c ra:raList){ if(RAUMap.containsKey(ra.Id)){ RAUMap.get(ra.Id).ShareStrategicUser__c = ra.ShareStrategicUser__c; }else{ RAUMap.put(ra.Id, ra); } } } // 20210924 ljh SFDC-C758NB update 优化 end //更新 if (RAUMap.size() > 0) { update RAUMap.values(); } /* //更新 if(ratList.size()>0){ update ratList; } //更新 if(raoList.size()>0){ update raoList; }//20210728 ljh SFDC-C5645S 注释*/ } private void dataCheck() { Map dataCheckMap = new Map(); List oPDPlanList = new List(); Map dataOPDMap = new Map(); for (Rental_Apply__c newObj : newList) { Rental_Apply__c oldObj = oldMap == null ? null : oldMap.get(newObj.Id); Boolean changeFlag = false; if (oldObj == null) { //新增 //1.获取 opd计划上记录的 原备品借出申请Id 获取31个相关字段的值 与当前值作比较 dataCheckMap.put(newObj.OPDPlan__c, newObj); } else { //应该有一个 补充申请创建 判断 //变更 //有31个字段的值不可修改 if (newObj.SupplementCreated__c) { changeFlag = RentalApplydataCheck(null, newObj, oldObj); if (System.Test.isRunningTest() == false && changeFlag) { newObj.addError('关联的OPD计划为补充OPD计划 不能编辑备品借用信息'); } //system.debug('changeFlag---->'+changeFlag); } } } if (dataCheckMap.size() > 0) { //查询 OPD计划 oPDPlanList = [SELECT Id, Name, supplementaryApplication__c, originalOpdRentalApply__c, OriginalOpdPlanApplication__c, OriginalOpdPlanApplication__r.Rental_Apply2__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Person_In_Charge__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.applyUser__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.ApplyPerson_Phone__c , OriginalOpdPlanApplication__r.Rental_Apply2__r.Hospital__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Strategic_dept__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Account__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_medical_Staff__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Phone_number__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose1__c , OriginalOpdPlanApplication__r.Rental_Apply2__r.demo_purpose2__c , OriginalOpdPlanApplication__r.Rental_Apply2__r.Product_category__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.AnimalExerimentFlag__c , OriginalOpdPlanApplication__r.Rental_Apply2__r.Campaign__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose_text__c , OriginalOpdPlanApplication__r.Rental_Apply2__r.Repair__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Follow_UP_Opp__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.CrinicalTrialName__c , OriginalOpdPlanApplication__r.Rental_Apply2__r.DB_loaner_request__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_demo_detail__c , OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_shipping_day__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_return_day__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Shipment_address__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Dealer__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff__c , OriginalOpdPlanApplication__r.Rental_Apply2__r.direct_shippment_address__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.direct_send__c , OriginalOpdPlanApplication__r.Rental_Apply2__r.pickup_time__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff_phone__c , OriginalOpdPlanApplication__r.Rental_Apply2__r.Post_Code__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.GI_Diff__c , OriginalOpdPlanApplication__r.Rental_Apply2__r.Hope_Lonaer_date_Num__c, OriginalOpdPlanApplication__r.Rental_Apply2__r.Name, OriginalOpdPlanApplication__r.Rental_Apply2__r.Id, OriginalOpdPlanApplication__r.Rental_Apply2__r.Rental_Apply_Equipment_Set_Cnt__c FROM OPDPlan__c WHERE Id In:dataCheckMap.keySet() ]; String sqlName = ''; String newName = ''; for (OPDPlan__c opd : oPDPlanList) { //OPD计划 通过 补充申请创建 if (opd.supplementaryApplication__c) { dataOPDMap.put(opd.Id, opd); String oldRaName = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Name; sqlName = oldRaName.indexOf('_') >= 0 ? oldRaName.split('_')[0] : oldRaName; sqlName = sqlName + '%'; } } if (dataOPDMap.size() > 0) { String rootRentalApplyId = null; if (String.isNotBlank(sqlName)) { List oldRaList = new List(); oldRaList = [select Id, Name from Rental_Apply__c where Name like :sqlName order by Name]; if (oldRaList.size() > 0) { rootRentalApplyId = oldRaList[0].Id; Integer num = oldRaList.size(); newName = sqlName.split('%')[0] + '_' + num; } else { newName = sqlName.split('%')[0] + '_' + 1; } } for (Rental_Apply__c newObj : newList) { Rental_Apply__c oldObj = oldMap == null ? null : oldMap.get(newObj.Id); Boolean changeFlag = false; if (oldObj == null) { //通过补充申请创建 备品借出申请 if (dataOPDMap.containskey(newObj.OPDPlan__c)) { OPDPlan__c opd = dataOPDMap.get(newObj.OPDPlan__c); newObj.Request_return_day__c = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_return_day__c; changeFlag = RentalApplydataCheck(opd, newObj, null); if (System.Test.isRunningTest() == false && changeFlag) { newObj.addError('关联的OPD计划为补充OPD计划 不能编辑备品借用信息'); } newObj.Old_Rental_Apply__c = opd.OriginalOpdPlanApplication__r.Rental_Apply2__c; newObj.Split_Apply_Reason__c = '补充借用'; newObj.SupplementCreated__c = true; newObj.Name = newName; newObj.Root_Rental_Apply__c = rootRentalApplyId; newObj.OriginalOpdPlanApplication__c = opd.OriginalOpdPlanApplication__c; } } } } } } private Boolean RentalApplydataCheck(OPDPlan__c opd, Rental_Apply__c newObj, Rental_Apply__c oldObj) { //新增 Boolean changeFlag = false; if (opd != null ) { Boolean Person_In_Charge = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Person_In_Charge__c != newObj.Person_In_Charge__c; system.debug('Person_In_Charge__c--->' + Person_In_Charge); Boolean applyUser = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.applyUser__c != newObj.applyUser__c; system.debug('applyUser--->' + applyUser); Boolean ApplyPerson_Phone = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.ApplyPerson_Phone__c != newObj.ApplyPerson_Phone__c; system.debug('ApplyPerson_Phone--->' + ApplyPerson_Phone); boolean Hospital = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Hospital__c != newObj.Hospital__c; system.debug('Hospital__c--->' + Hospital); boolean Strategic_dept = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Strategic_dept__c != newObj.Strategic_dept__c; system.debug('Strategic_dept__c--->' + Strategic_dept); boolean Account = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Account__c != newObj.Account__c; system.debug('Account__c--->' + Account); boolean Loaner_medical_Staff = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_medical_Staff__c != newObj.Loaner_medical_Staff__c; system.debug('Loaner_medical_Staff__c--->' + Loaner_medical_Staff); boolean Phone_number = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Phone_number__c != newObj.Phone_number__c; system.debug('Phone_number__c--->' + Phone_number); boolean Demo_purpose1 = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose1__c != newObj.Demo_purpose1__c; system.debug('Demo_purpose1__c--->' + Demo_purpose1); boolean demo_purpose2 = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.demo_purpose2__c != newObj.demo_purpose2__c; system.debug('demo_purpose2__c--->' + demo_purpose2); boolean Product_category = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Product_category__c != newObj.Product_category__c; system.debug('Product_category__c--->' + Product_category); boolean AnimalExerimentFlag = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.AnimalExerimentFlag__c != newObj.AnimalExerimentFlag__c; system.debug('AnimalExerimentFlag__c--->' + AnimalExerimentFlag); boolean Campaign = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Campaign__c != newObj.Campaign__c; system.debug('Campaign__c--->' + Campaign); boolean Demo_purpose_text = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose_text__c != newObj.Demo_purpose_text__c; system.debug('Demo_purpose_text__c--->' + Demo_purpose_text); boolean Repair = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Repair__c != newObj.Repair__c; system.debug('Repair__c--->' + Repair); boolean Follow_UP_Opp = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Follow_UP_Opp__c != newObj.Follow_UP_Opp__c; system.debug('Follow_UP_Opp__c--->' + Follow_UP_Opp); boolean CrinicalTrialName = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.CrinicalTrialName__c != newObj.CrinicalTrialName__c; system.debug('CrinicalTrialName__c--->' + CrinicalTrialName); boolean DB_loaner_request = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.DB_loaner_request__c != newObj.DB_loaner_request__c; system.debug('DB_loaner_request__c--->' + DB_loaner_request); boolean Request_demo_detail = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_demo_detail__c != newObj.Request_demo_detail__c; system.debug('Request_demo_detail__c--->' + Request_demo_detail); //boolean Request_shipping_day = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_shipping_day__c != newObj.Request_shipping_day__c; //system.debug('Request_shipping_day__c--->'+Request_shipping_day); boolean Request_return_day = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_return_day__c != newObj.Request_return_day__c; system.debug('Request_return_day__c--->' + Request_return_day); boolean Shipment_address = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Shipment_address__c != newObj.Shipment_address__c; system.debug('Shipment_address__c--->' + Shipment_address); boolean Dealer = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Dealer__c != newObj.Dealer__c; system.debug('Dealer__c--->' + Dealer); boolean Loaner_received_staff = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff__c != newObj.Loaner_received_staff__c; system.debug('Loaner_received_staff__c--->' + Loaner_received_staff); boolean direct_shippment_address = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.direct_shippment_address__c != newObj.direct_shippment_address__c; system.debug('direct_shippment_address__c--->' + direct_shippment_address); boolean direct_send = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.direct_send__c != newObj.direct_send__c; system.debug('direct_send__c--->' + direct_send); boolean pickup_time = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.pickup_time__c != newObj.pickup_time__c; system.debug('pickup_time__c--->' + pickup_time); boolean Loaner_received_staff_phone = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff_phone__c != newObj.Loaner_received_staff_phone__c; system.debug('Loaner_received_staff_phone__c--->' + Loaner_received_staff_phone); boolean Post_Code = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Post_Code__c != newObj.Post_Code__c; system.debug('Post_Code__c--->' + Post_Code); boolean GI_Diff = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.GI_Diff__c != newObj.GI_Diff__c; system.debug('GI_Diff__c--->' + GI_Diff); boolean Hope_Lonaer_date_Num = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Hope_Lonaer_date_Num__c != newObj.Hope_Lonaer_date_Num__c ; system.debug('Hope_Lonaer_date_Num__c--->' + Hope_Lonaer_date_Num); changeFlag = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Person_In_Charge__c != newObj.Person_In_Charge__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.applyUser__c != newObj.applyUser__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.ApplyPerson_Phone__c != newObj.ApplyPerson_Phone__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Hospital__c != newObj.Hospital__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Strategic_dept__c != newObj.Strategic_dept__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Account__c != newObj.Account__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_medical_Staff__c != newObj.Loaner_medical_Staff__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Phone_number__c != newObj.Phone_number__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose1__c != newObj.Demo_purpose1__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.demo_purpose2__c != newObj.demo_purpose2__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Product_category__c != newObj.Product_category__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.AnimalExerimentFlag__c != newObj.AnimalExerimentFlag__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Campaign__c != newObj.Campaign__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose_text__c != newObj.Demo_purpose_text__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Repair__c != newObj.Repair__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Follow_UP_Opp__c != newObj.Follow_UP_Opp__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.CrinicalTrialName__c != newObj.CrinicalTrialName__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.DB_loaner_request__c != newObj.DB_loaner_request__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_demo_detail__c != newObj.Request_demo_detail__c || //opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_shipping_day__c != newObj.Request_shipping_day__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_return_day__c != newObj.Request_return_day__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Shipment_address__c != newObj.Shipment_address__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Dealer__c != newObj.Dealer__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff__c != newObj.Loaner_received_staff__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.direct_shippment_address__c != newObj.direct_shippment_address__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.direct_send__c != newObj.direct_send__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.pickup_time__c != newObj.pickup_time__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff_phone__c != newObj.Loaner_received_staff_phone__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Post_Code__c != newObj.Post_Code__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.GI_Diff__c != newObj.GI_Diff__c || opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Hope_Lonaer_date_Num__c != newObj.Hope_Lonaer_date_Num__c ; } else { changeFlag = newObj.Person_In_Charge__c != oldObj.Person_In_Charge__c || newObj.applyUser__c != oldObj.applyUser__c || newObj.ApplyPerson_Phone__c != oldObj.ApplyPerson_Phone__c || newObj.Hospital__c != oldObj.Hospital__c || newObj.Strategic_dept__c != oldObj.Strategic_dept__c || newObj.Account__c != oldObj.Account__c || newObj.Loaner_medical_Staff__c != oldObj.Loaner_medical_Staff__c || newObj.Phone_number__c != oldObj.Phone_number__c || newObj.Demo_purpose1__c != oldObj.Demo_purpose1__c || newObj.demo_purpose2__c != oldObj.demo_purpose2__c || newObj.Product_category__c != oldObj.Product_category__c || newObj.AnimalExerimentFlag__c != oldObj.AnimalExerimentFlag__c || newObj.Campaign__c != oldObj.Campaign__c || newObj.Demo_purpose_text__c != oldObj.Demo_purpose_text__c || newObj.Repair__c != oldObj.Repair__c || newObj.Follow_UP_Opp__c != oldObj.Follow_UP_Opp__c || newObj.CrinicalTrialName__c != oldObj.CrinicalTrialName__c || newObj.DB_loaner_request__c != oldObj.DB_loaner_request__c || newObj.Request_demo_detail__c != oldObj.Request_demo_detail__c || //newObj.Request_shipping_day__c != oldObj.Request_shipping_day__c || newObj.Request_return_day__c != oldObj.Request_return_day__c || newObj.Shipment_address__c != oldObj.Shipment_address__c || newObj.Dealer__c != oldObj.Dealer__c || newObj.Loaner_received_staff__c != oldObj.Loaner_received_staff__c || newObj.direct_shippment_address__c != oldObj.direct_shippment_address__c || newObj.direct_send__c != oldObj.direct_send__c || newObj.pickup_time__c != oldObj.pickup_time__c || newObj.Loaner_received_staff_phone__c != oldObj.Loaner_received_staff_phone__c || newObj.Post_Code__c != oldObj.Post_Code__c || newObj.GI_Diff__c != oldObj.GI_Diff__c || newObj.Hope_Lonaer_date_Num__c != oldObj.Hope_Lonaer_date_Num__c; } return changeFlag; } }