| | |
| | | public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); |
| | | public static String sobjectTypeValue = 'Address__c'; |
| | | public Boolean isNewMode{set;get;} |
| | | public Boolean isCloneMode{protected set;get;} |
| | | public String rtTypeId {get; set;} |
| | | public String AWSDataId{set;get;} |
| | | public String contactId{set;get;}//For Lookup field |
| | |
| | | public String sobjecttypeForFrontEnd{set;get;} |
| | | public String contactsInfo {set;get;}//key sfid;value awsid |
| | | public String layoutSectionsStr {get; set;} |
| | | public String VLookUpFieldsJson{get;private set;} |
| | | // public String CurrentUserId{private set; get;} |
| | | // public String CurrentUserName{private set; get;} |
| | | //zhj MEBG新方案改造 2022-11-29 start |
| | | public String staticResourceV2 {get; set;} |
| | | //zhj MEBG新方案改造 2022-11-29 end |
| | | public NewAndEditAddressController(ApexPages.StandardController controller) { |
| | | isNewMode = true; |
| | | isCloneMode = false; |
| | | Input_Required_Field_Msg = Label.Input_Required_Field_Msg; |
| | | PIPL_Name_Label = Label.PIPL_Name_Label; |
| | | PIPL_Input_Account_Error_Msg = label.PIPL_Input_Account_Error_Msg; |
| | |
| | | List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Address__c').getDescribe().fields.getMap().keyset()); |
| | | // Add fields to controller. This is to avoid the SOQL error in visualforce page |
| | | if (!Test.isRunningTest()) { |
| | | controller.addFields(fieldList);} |
| | | controller.addFields(fieldList); |
| | | } |
| | | Map<string,string> mso = ApexPages.currentPage().getParameters(); |
| | | if(mso != null && mso.containsKey('newclone')){ |
| | | isCloneMode = true; |
| | | } |
| | | SObject obj = controller.getRecord(); |
| | | if(obj.Id != null){ |
| | | //更新 |
| | |
| | | Address__c addressData = [select Id, RecordTypeId, AWS_Data_Id__c, Contacts__r.Id, Contacts__r.AWS_Data_Id__c from Address__c where id =: obj.Id]; |
| | | rtTypeId = addressData.RecordTypeId; |
| | | AWSDataId = addressData.AWS_Data_Id__c; |
| | | Map<String,String> sfIdToAWSIdMap = new Map<String,String>(); |
| | | // if(addressData.Contacts__r.Id != null){ |
| | | // sfIdToAWSIdMap.put(String.valueof(addressData.Contacts__r.Id).subString(0,15),addressData.Contacts__r.AWS_Data_Id__c); |
| | | // } |
| | | sfIdToAWSIdMap.put(String.valueof(addressData.Contacts__r.Id).subString(0,15),addressData.Contacts__r.AWS_Data_Id__c); |
| | | contactsInfo = JSON.serialize(sfIdToAWSIdMap); |
| | | //zhj PIPL 2022-06-24 start |
| | | // Map<String,String> sfIdToAWSIdMap = new Map<String,String>(); |
| | | // // if(addressData.Contacts__r.Id != null){ |
| | | // // sfIdToAWSIdMap.put(String.valueof(addressData.Contacts__r.Id).subString(0,15),addressData.Contacts__r.AWS_Data_Id__c); |
| | | // // } |
| | | // sfIdToAWSIdMap.put(String.valueof(addressData.Contacts__r.Id).subString(0,15),addressData.Contacts__r.AWS_Data_Id__c); |
| | | // contactsInfo = JSON.serialize(sfIdToAWSIdMap); |
| | | //zhj PIPL 2022-06-24 end |
| | | }else{ |
| | | //新建 |
| | | rtTypeId = ApexPages.currentPage().getParameters().get('RecordType'); |
| | |
| | | encryptedAPIList = piIntegration.PIFields; |
| | | sobjectPrefix = piIntegration.sobjectPrefix; |
| | | layoutSectionsStr = JSON.serialize(layoutSections); |
| | | //获取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); |
| | | //zhj MEBG新方案改造 2022-11-29 start |
| | | staticResourceV2 = JSON.serialize(PIHelper.getPIIntegrationInfo('Address__cV2')); |
| | | //zhj MEBG新方案改造 2022-11-29 end |
| | | // CurrentUserName = UserInfo.getName(); |
| | | // CurrentUserId = UserInfo.getUserId(); |
| | | } |
| | |
| | | if(String.isNotBlank(dt)&&dt.contains('T')){ |
| | | dt = dt.replace('T',' '); |
| | | addressInfo.put(fieldAPI, Datetime.valueOfGmt(dt)); |
| | | }else { |
| | | addressInfo.put(fieldAPI,fieldValue); |
| | | }else if(String.isNotBlank(fieldValue)) { |
| | | fieldValue = fieldValue.replace('/', '-') + ':00'; |
| | | addressInfo.put(fieldAPI, Datetime.valueOf(fieldValue)); |
| | | }else{ |
| | | addressInfo.put(fieldAPI,null); |
| | | } |
| | | }else if(String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){ |
| | | addressInfo.put(fieldAPI, (String.isBlank(fieldValue)||String.isEmpty(fieldValue))?null:Decimal.valueOf(fieldValue.replace(',', ''))); |
| | |
| | | String status = 'success'; |
| | | Response resp = new Response(); |
| | | Savepoint sp = Database.setSavepoint(); |
| | | Boolean isClone = false; |
| | | // String rid = ''; |
| | | String awsDataId = ''; |
| | | try{ |
| | | System.debug('abcde'); |
| | | if(isNew){ |
| | | awsDataId = (String)addressInfo.get('AWS_Data_Id__c'); |
| | | System.debug('awsDataId = ' + awsDataId); |
| | | Address__c[] addresses = [select id from Address__c where AWS_Data_Id__c =:awsDataId]; |
| | | if(!isNew){ |
| | | isClone = addresses.size() == 0; |
| | | } |
| | | System.debug('isClone---------'+isClone); |
| | | if(isNew || isClone){ |
| | | System.debug('addressInfoNancy = ' + addressInfo); |
| | | insert addressInfo; |
| | | }else{ |
| | | System.debug('into update'); |
| | | awsDataId = (String)addressInfo.get('AWS_Data_Id__c'); |
| | | System.debug('awsDataId = ' + awsDataId); |
| | | Address__c[] addresses = [select id from Address__c where AWS_Data_Id__c =:awsDataId]; |
| | | // awsDataId = (String)addressInfo.get('AWS_Data_Id__c'); |
| | | // System.debug('awsDataId = ' + awsDataId); |
| | | // Address__c[] addresses = [select id from Address__c where AWS_Data_Id__c =:awsDataId]; |
| | | System.debug('addresses[0].id = ' + addresses[0].id); |
| | | addressInfo.put('Id',addresses[0].id);//For testing; |
| | | update addressInfo; |