| | |
| | | public Map<string,string> AWSToSobjectEncryptedMap{get;private set;} |
| | | public string AWSToSobjectEncryptedMapJson{get{return JSON.serialize(AWSToSobjectEncryptedMap);}} |
| | | public String sfRecordIdForEdit{set;get;}//Add By LiJun for Edit Record from NFM609, 20220510 |
| | | public String VLookUpFieldsJson{get;private set;} |
| | | //zhj MEBG新方案改造 2022-11-29 start |
| | | public String staticResourceV2 {get; set;} |
| | | //zhj MEBG新方案改造 2022-11-29 end |
| | | public NewAndEditCaseController(ApexPages.StandardController controller) { |
| | | isNewMode = true; |
| | | isCloneMode = false; |
| | |
| | | }else{ |
| | | //新建 |
| | | // rtTypeId = ApexPages.currentPage().getParameters().get('RecordType'); |
| | | AssignValueFromUrl(mso,controller.getRecord()); |
| | | rtTypeId = mso.get('RecordType'); |
| | | obj.put('OwnerId',UserInfo.getUserId()); |
| | | } |
| | |
| | | sobjectPrefix = piIntegration.sobjectPrefix; |
| | | layoutSectionsStr = JSON.serialize(layoutSections); |
| | | AWSToSobjectEncryptedMap = new Map<String,String>(); |
| | | |
| | | //获取lookup字段 |
| | | List<String> VLookUpFields = new List<String>(); |
| | | for (LayoutDescriberHelper.LayoutSection ls : layoutSections) { |
| | | for (LayoutDescriberHelper.LayoutField lf : ls.layoutFields) { |
| | | if (lf.fieldAPI != '' && lf.fieldType == 'reference') { |
| | | VLookUpFields.add(lf.fieldAPI); |
| | | } |
| | | } |
| | | } |
| | | VLookUpFieldsJson = Json.serialize(VLookUpFields); |
| | | for (PI_Field_Policy_Detail__c PIDetail : piIntegration.PIDetails) { |
| | | AWSToSobjectEncryptedMap.put(PIDetail.AWS_Field_API__c, PIDetail.SF_Field_API_Name__c); |
| | | } |
| | | //zhj MEBG新方案改造 2022-11-29 start |
| | | staticResourceV2 = JSON.serialize(PIHelper.getPIIntegrationInfo('CaseV2')); |
| | | //zhj MEBG新方案改造 2022-11-29 end |
| | | } |
| | | global class Response{ |
| | | public String recordId{set;get;} |
| | |
| | | return resp; |
| | | } |
| | | } |
| | | |
| | | public static void AssignValueFromUrl(Map<string,string> mso, sobject sobj){ |
| | | |
| | | String sobject_name = sobj.getSObjectType().getDescribe().getName(); |
| | | Map<string,object> temp = new Map<string,object>(); |
| | | Map<string,FieldDefinition> fdm = new Map<string,FieldDefinition>(); |
| | | List<FieldDefinition> fds = [SELECT Id, DurableId, QualifiedApiName,ValueTypeId , EntityDefinitionId, NamespacePrefix,EntityDefinition.NamespacePrefix, DeveloperName, MasterLabel, Label FROM FieldDefinition where EntityDefinition.QualifiedApiName = :sobject_name]; |
| | | for(FieldDefinition fd : fds){ |
| | | //system.debug(fd.DurableId); |
| | | fdm.put(fd.DurableId.split('\\.')[1],fd); |
| | | } |
| | | |
| | | for(string key : mso.keySet()){ |
| | | if (key.toLowerCase() == 'id') { |
| | | System.debug('skip id assign'); |
| | | continue; |
| | | } |
| | | string new_key = key; |
| | | system.debug('new_key='+new_key); |
| | | if(new_key.contains('_lkid')){ |
| | | new_key = new_key.replace('_lkid', ''); |
| | | new_key = new_key.substring(2); |
| | | }else{ |
| | | if(temp.containsKey(new_key)){ |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | system.debug('now new_key='+new_key); |
| | | if(fdm.containsKey(new_key)){ |
| | | system.debug('fdm.get(new_key)='+fdm.get(new_key)); |
| | | string val_str = mso.get(key); |
| | | system.debug('val_str='+val_str); |
| | | /*无需做decode,sf内部已经做好 |
| | | try{ |
| | | val_str = EncodingUtil.urlDecode(mso.get(key),'UTF-8'); |
| | | }catch(Exception e){ |
| | | continue; |
| | | system.debug('Exception from get Key:'+e.getMessage()); |
| | | system.debug(e.getStackTraceString()); |
| | | } */ |
| | | object val = null; |
| | | string type_id = fdm.get(new_key).ValueTypeId; |
| | | // address, boolean, date, datetime, double, id, location, string, time |
| | | if(string.isBlank(val_str)){ |
| | | val = null; |
| | | }else if(type_id == 'boolean'){ |
| | | if(val_str == '1'){ |
| | | val = true; |
| | | }else{ |
| | | val = boolean.valueOf(val_str); |
| | | } |
| | | }else if(type_id == 'date'){ |
| | | // |
| | | try{ |
| | | val = date.parse(val_str); |
| | | }catch(Exception e){ |
| | | system.debug('val_str='+val_str); |
| | | system.debug(e.getMessage()); |
| | | system.debug(e.getStackTraceString()); |
| | | try{ |
| | | val = date.valueOf(val_str); |
| | | }catch(Exception ee){ |
| | | system.debug('val_str='+val_str); |
| | | system.debug(ee.getMessage()); |
| | | system.debug(ee.getStackTraceString()); |
| | | continue; |
| | | } |
| | | } |
| | | }else if(type_id == 'datetime'){ |
| | | // |
| | | try{ |
| | | val = datetime.parse(val_str); |
| | | }catch(Exception e){ |
| | | system.debug('val_str='+val_str); |
| | | system.debug(e.getMessage()); |
| | | system.debug(e.getStackTraceString()); |
| | | try{ |
| | | val = datetime.valueOf(val_str); |
| | | }catch(Exception ee){ |
| | | system.debug('val_str='+val_str); |
| | | system.debug(ee.getMessage()); |
| | | system.debug(ee.getStackTraceString()); |
| | | continue; |
| | | } |
| | | } |
| | | }else if(type_id == 'double' || type_id == 'number'){ |
| | | try{ |
| | | val = decimal.valueOf(val_str.replace(',', '')); |
| | | }catch(Exception ee){ |
| | | system.debug('val_str='+val_str); |
| | | system.debug(ee.getMessage()); |
| | | system.debug(ee.getStackTraceString()); |
| | | continue; |
| | | } |
| | | |
| | | }else if(type_id == 'id' || type_id == 'string'){ |
| | | val = val_str; |
| | | }else{ |
| | | system.debug('type_id='+type_id+' is not support to convert'); |
| | | continue; |
| | | } |
| | | temp.put(fdm.get(new_key).QualifiedApiName,val); |
| | | }else{ |
| | | system.debug(key+' is not in fdm'); |
| | | } |
| | | } |
| | | |
| | | for(string key : temp.keySet()){ |
| | | system.debug('assign '+key+'='+temp.get(key)); |
| | | try{ |
| | | sobj.put(key, temp.get(key)); |
| | | }catch(Exception e){ |
| | | system.debug(e.getMessage()); |
| | | system.debug(e.getStackTraceString()); |
| | | } |
| | | } |
| | | } |
| | | } |