From f5a94e721ae5a26f817f0df75065b64f1f192eb3 Mon Sep 17 00:00:00 2001 From: Li Jun <buli@deloitte.com.cn> Date: 星期一, 28 三月 2022 21:43:51 +0800 Subject: [PATCH] PIPLFunctionDeploy0328 --- force-app/main/default/classes/RentalApplyController.cls | 83 ++++++++++++++++++++++++++++++++++++----- 1 files changed, 73 insertions(+), 10 deletions(-) diff --git a/force-app/main/default/classes/RentalApplyController.cls b/force-app/main/default/classes/RentalApplyController.cls index 1a23237..e38bb9f 100644 --- a/force-app/main/default/classes/RentalApplyController.cls +++ b/force-app/main/default/classes/RentalApplyController.cls @@ -2,10 +2,11 @@ * @description : * @author : ChangeMeIn@UserSettingsUnder.SFDoc * @group : - * @last modified on : 03-11-2022 + * @last modified on : 03-28-2022 * @last modified by : ChangeMeIn@UserSettingsUnder.SFDoc **/ global without sharing class RentalApplyController { + public String layoutSectionsStr {get; set;}//for dynamic add readonly attribute public List <LayoutDescriberHelper.LayoutSection > layoutSections{set;get;} public String awsToken{set;get;} public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); @@ -29,7 +30,9 @@ PIPL_Input_Account_Error_Msg = label.PIPL_Input_Account_Error_Msg; //鑾峰彇鎵�鏈夊瓧娈� List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Rental_Apply__c').getDescribe().fields.getMap().keyset()); - controller.addFields(fieldList); + if(!Test.isRunningTest()){ + controller.addFields(fieldList); + } SObject obj = controller.getRecord(); if(obj.Id != null){ //鏇存柊 @@ -38,14 +41,47 @@ rtTypeId = rentalApplyData.RecordTypeId; AWSDataId = rentalApplyData.AWS_Data_Id__c; Map<String,String> sfIdToAWSIdMap = new Map<String,String>(); - sfIdToAWSIdMap.put(String.valueof(rentalApplyData.Loaner_medical_Staff__r.Id).subString(0,15),rentalApplyData.Loaner_medical_Staff__r.AWS_Data_Id__c); + if(rentalApplyData.Loaner_medical_Staff__r.Id != null){ + sfIdToAWSIdMap.put(String.valueof(rentalApplyData.Loaner_medical_Staff__r.Id).subString(0,15),rentalApplyData.Loaner_medical_Staff__r.AWS_Data_Id__c); + } contactsInfo = JSON.serialize(sfIdToAWSIdMap); }else{ //鏂板缓 + Map<string,string> mso = ApexPages.currentPage().getParameters(); + system.debug('mso='+mso); + if(mso.containsKey('Name')){ + controller.getRecord().put('Name',mso.get('Name')); + } + if(mso.containsKey('CF00N10000008ps61_lkid')){ + controller.getRecord().put('OPDPlan__c',mso.get('CF00N10000008ps61_lkid')); + } + if(mso.containsKey('CF00N10000003Mp1d_lkid')){ + controller.getRecord().put('Hospital__c',mso.get('CF00N10000003Mp1d_lkid')); + } + if(mso.containsKey('CF00N10000003O3V6_lkid')){ + controller.getRecord().put('Strategic_dept__c',mso.get('CF00N10000003O3V6_lkid')); + } + if(mso.containsKey('CF00N10000003Mp2R_lkid')){ + controller.getRecord().put('Account__c',mso.get('CF00N10000003Mp2R_lkid')); + } + if(mso.containsKey('00N10000003Msk0')){ + controller.getRecord().put('Demo_purpose1__c',mso.get('00N10000003Msk0')); + } + if(mso.containsKey('00N10000003Msk5')){ + controller.getRecord().put('demo_purpose2__c',mso.get('00N10000003Msk5')); + } + if(mso.containsKey('00N100000098amW')){ + controller.getRecord().put('NoOpp_Reason__c',mso.get('00N100000098amW')); + } + if(mso.containsKey('00N10000003OJzc')){ + controller.getRecord().put('Loaner_received_staff__c',mso.get('00N10000003OJzc')); + } rtTypeId = ApexPages.currentPage().getParameters().get('RecordType'); + obj.put('OwnerId',UserInfo.getUserId()); } LayoutDescriberHelper.LayoutWrapper LayoutWrapperValue = LayoutDescriberHelper.describeSectionWithFieldsWrapper(rtTypeId, 'Rental_Apply__c','classic'); layoutSections = LayoutWrapperValue.layoutSections; + layoutSectionsStr = JSON.serialize(layoutSections); //for dynamic add readonly attribute List<String> requiredFieldAPIList = LayoutWrapperValue.requiredFieldAPIList; Map<String,String> fieldAPIToLabelMap = LayoutWrapperValue.fieldAPIToLabelMap; requiredFieldAPIListStr = JSON.serialize(requiredFieldAPIList); @@ -72,25 +108,32 @@ Rental_Apply__c rentalApplyInfo = new Rental_Apply__c(); //鑷畾涔夋牸寮忚浆鎹� for (String fieldAPI: fieldValueMap.keySet()) { - system.debug('field API='+fieldAPI); + system.debug('field API'+fieldAPI); + if(!fieldAPIToTypeMap.containskey(fieldAPI)){ + continue; + } Schema.DisplayType fielddataType = fieldAPIToTypeMap.get(fieldAPI).getDescribe().getType(); String fieldValue = String.valueOf(fieldValueMap.get(fieldAPI)); - system.debug('Field Type:'+fielddataType+' field Value='+fieldValue); if(String.valueOf(fielddataType)=='DATE'){ - rentalApplyInfo.put(fieldAPI,(String.isBlank(fieldValue)||String.isEmpty(fieldValue))? null:Date.valueOf(fieldValue.replace('/', '-'))); + rentalApplyInfo.put(fieldAPI,(String.isBlank(fieldValue)||String.isEmpty(fieldValue))? null:Date.valueOf(fieldValue.replace('/', '-'))); }else if(String.valueOf(fielddataType)=='DATETIME'){ if(String.isNotBlank(fieldValue)&&fieldValue.contains('T')){ fieldValue = fieldValue.replace('T',' '); rentalApplyInfo.put(fieldAPI, Datetime.valueOfGmt(fieldValue)); + }else if(String.isNotBlank(fieldValue)) { + fieldValue = fieldValue.replace('/', '-') + ':00'; + System.debug('fieldValue = ' + fieldValue); + rentalApplyInfo.put(fieldAPI, Datetime.valueOf(fieldValue)); }else{ rentalApplyInfo.put(fieldAPI, null); - } - }else if(String.valueof(fielddataType)=='CURRENCY'|| String.valueof(fielddataType)=='PERCENT'||String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){ - rentalApplyInfo.put(fieldAPI, (String.isBlank(fieldValue)||String.isEmpty(fieldValue))?0:Decimal.valueOf(fieldValue)); + } + + }else if(String.valueOf(fielddataType)=='PERCENT'||String.valueOf(fielddataType)=='CURRENCY'||String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){ + rentalApplyInfo.put(fieldAPI, (String.isBlank(fieldValue)||String.isEmpty(fieldValue))?null:Decimal.valueOf(fieldValue.replace(',', ''))); } else if(String.valueof(fielddataType)=='BOOLEAN'){ rentalApplyInfo.put(fieldAPI, fieldValueMap.get(fieldAPI)); }else { - rentalApplyInfo.put(fieldAPI,fieldValue); + rentalApplyInfo.put(fieldAPI, String.valueOf(fieldValueMap.get(fieldAPI))); } } @@ -122,6 +165,26 @@ resp.status = status; System.debug('respzhj = ' + resp); return resp; + } catch(DmlException e) { + rid=rentalApplyInfo.Id; + Integer index = 0; + System.debug(e.getNumDml()); + System.debug(e.getDmlFields(index)); + System.debug(e.getDmlId(index)); + System.debug(e.getDmlIndex(index)); + System.debug(e.getDmlMessage(index)); + System.debug(e.getDmlStatusCode(index)); + System.debug(e.getDmlType(index)); + system.debug(e.getMessage()); + system.debug(e.getStackTraceString()); + + System.debug('into catch'+e.getMessage()); + Database.rollback(sp); + resp.status = 'Exception'; + resp.message ='淇濆瓨澶辫触锛屽師鍥�:'+ e.getDmlMessage(index); + PIHelper.saveTransLog(sobjectTypeValue,rid,transId, (String)rentalApplyInfo.get('AWS_Data_Id__c'),rentalApplyJson ,status,''); + return resp; + } catch(Exception e) { System.debug('into catch'+e.getMessage()); Database.rollback(sp); -- Gitblit v1.9.1