| | |
| | | /** |
| | | * @description : |
| | | * @author : ChangeMeIn@UserSettingsUnder.SFDoc |
| | | * @group : |
| | | * @last modified on : 03-17-2022 |
| | | * @last modified by : ChangeMeIn@UserSettingsUnder.SFDoc |
| | | **/ |
| | | global without sharing class OnCallController { |
| | | 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(); |
| | |
| | | }else{ |
| | | //新建 |
| | | rtTypeId = null; |
| | | obj.put('OwnerId',UserInfo.getUserId()); |
| | | } |
| | | LayoutDescriberHelper.LayoutWrapper LayoutWrapperValue = LayoutDescriberHelper.describeSectionWithFieldsWrapper(rtTypeId, 'On_Call__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); |
| | |
| | | On_Call__c onCallInfo = new On_Call__c(); |
| | | //自定义格式转换 |
| | | for (String fieldAPI: fieldValueMap.keySet()) { |
| | | system.debug('field API'+fieldAPI); |
| | | system.debug('field API='+fieldAPI); |
| | | Schema.DisplayType fielddataType = fieldAPIToTypeMap.get(fieldAPI).getDescribe().getType(); |
| | | String fieldValue = String.valueOf(fieldValueMap.get(fieldAPI)); |
| | | if(String.isBlank(fieldValue)){ |
| | | continue; |
| | | } |
| | | system.debug('Field Type:'+fielddataType+' field Value='+fieldValue); |
| | | if(String.valueOf(fielddataType)=='DATE'){ |
| | | onCallInfo.put(fieldAPI, Date.valueOf(String.valueOf(fieldValueMap.get(fieldAPI)).replace('/', '-'))); |
| | | onCallInfo.put(fieldAPI,(String.isBlank(fieldValue)||String.isEmpty(fieldValue))? null:Date.valueOf(fieldValue.replace('/', '-'))); |
| | | }else if(String.valueOf(fielddataType)=='DATETIME'){ |
| | | String dt = String.valueOf(fieldValueMap.get(fieldAPI)); |
| | | if(String.isNotBlank(dt)&&dt.contains('T')){ |
| | | dt = dt.replace('T',' '); |
| | | onCallInfo.put(fieldAPI, Datetime.valueOfGmt(dt)); |
| | | } |
| | | }else if(String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){ |
| | | onCallInfo.put(fieldAPI, Decimal.valueOf(String.valueOf(fieldValueMap.get(fieldAPI)))); |
| | | if(String.isNotBlank(fieldValue)&&fieldValue.contains('T')){ |
| | | fieldValue = fieldValue.replace('T',' '); |
| | | onCallInfo.put(fieldAPI, Datetime.valueOfGmt(fieldValue)); |
| | | }else{ |
| | | onCallInfo.put(fieldAPI, null); |
| | | } |
| | | }else if(String.valueof(fielddataType)=='CURRENCY'|| String.valueof(fielddataType)=='PERCENT'||String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){ |
| | | onCallInfo.put(fieldAPI, (String.isBlank(fieldValue)||String.isEmpty(fieldValue))?0:Decimal.valueOf(fieldValue)); |
| | | } else if(String.valueof(fielddataType)=='BOOLEAN'){ |
| | | onCallInfo.put(fieldAPI, fieldValueMap.get(fieldAPI)); |
| | | }else { |
| | | onCallInfo.put(fieldAPI, String.valueOf(fieldValueMap.get(fieldAPI))); |
| | | } |
| | | onCallInfo.put(fieldAPI,fieldValue); |
| | | } |
| | | } |
| | | |
| | | //2. Save Record Process |