| | |
| | | public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); |
| | | public static String sobjectTypeValue = 'Case'; |
| | | 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 final string ApiPrefix{get;private set;} //Add By Yin Mingjie 20220404 |
| | | 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 NewAndEditCaseController(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('Case').getDescribe().fields.getMap().keyset()); |
| | | // Add fields to controller. This is to avoid the SOQL error in visualforce page |
| | | Map<string,string> mso = ApexPages.currentPage().getParameters(); |
| | | if(mso != null && mso.containsKey('newclone')){ |
| | | isCloneMode = true; |
| | | } |
| | | if (!Test.isRunningTest()) { |
| | | controller.addFields(fieldList); |
| | | } |
| | |
| | | Case caseData = [select Id,RecordTypeId,AWS_Data_Id__c,ContactId,Contact.AWS_Data_Id__c from Case where id =: obj.Id]; |
| | | rtTypeId = caseData.RecordTypeId; |
| | | AWSDataId = caseData.AWS_Data_Id__c; |
| | | sfRecordIdForEdit = obj.Id;//Add By LiJun for Edit Record from NFM609, 20220510 |
| | | System.debug('AWSDataId=' + AWSDataId); |
| | | Map<String,String> sfIdToAWSIdMap = new Map<String,String>(); |
| | | if(caseData.ContactId != null){ |
| | |
| | | contactsInfo = JSON.serialize(sfIdToAWSIdMap); |
| | | }else{ |
| | | //新建 |
| | | rtTypeId = ApexPages.currentPage().getParameters().get('RecordType'); |
| | | // rtTypeId = ApexPages.currentPage().getParameters().get('RecordType'); |
| | | rtTypeId = mso.get('RecordType'); |
| | | obj.put('OwnerId',UserInfo.getUserId()); |
| | | } |
| | | LayoutDescriberHelper.LayoutWrapper LayoutWrapperValue = LayoutDescriberHelper.describeSectionWithFieldsWrapper(rtTypeId, 'Case','classic'); |
| | |
| | | encryptedAPIList = piIntegration.PIFields; |
| | | sobjectPrefix = piIntegration.sobjectPrefix; |
| | | layoutSectionsStr = JSON.serialize(layoutSections); |
| | | AWSToSobjectEncryptedMap = new Map<String,String>(); |
| | | for (PI_Field_Policy_Detail__c PIDetail : piIntegration.PIDetails) { |
| | | AWSToSobjectEncryptedMap.put(PIDetail.AWS_Field_API__c, PIDetail.SF_Field_API_Name__c); |
| | | } |
| | | } |
| | | global class Response{ |
| | | public String recordId{set;get;} |
| | |
| | | } |
| | | } |
| | | |
| | | System.debug('caseInfo='+caseInfo); |
| | | System.debug('caseInfo.Account__c='+caseInfo.Account__c); |
| | | if (!String.isBlank(caseInfo.ContactId) && (String.isBlank(caseInfo.Account__c) || Id.valueOf(caseInfo.Account__c).to15() =='000000000000000')) { |
| | | Contact c = [select id,AccountId from Contact where id = :caseInfo.ContactId]; |
| | | caseInfo.Account__c = c.AccountId; |
| | | if (Id.valueOf(caseInfo.ContactId).to15() !='000000000000000') { |
| | | Contact c = [select id,AccountId from Contact where id = :caseInfo.ContactId]; |
| | | caseInfo.Account__c = c.AccountId; |
| | | } |
| | | } |
| | | |
| | | //2. Save Record Process |
| | |
| | | Response resp = new Response(); |
| | | Savepoint sp = Database.setSavepoint(); |
| | | String rid = ''; |
| | | String awsDataId = ''; |
| | | String sfRecordId = ''; |
| | | Boolean isClone = false; |
| | | try{ |
| | | System.debug('abcde'); |
| | | if(isNew){ |
| | | awsDataId = (String)caseInfo.get('AWS_Data_Id__c'); |
| | | sfRecordId = (String)caseInfo.get('Id'); |
| | | System.debug('awsDataId = ' + awsDataId); |
| | | Case[] cases = [select id from Case where AWS_Data_Id__c =:awsDataId or id =:sfRecordId]; |
| | | |
| | | if(!isNew){ |
| | | isClone = cases.size() == 0; |
| | | } |
| | | system.debug('isClone'+isClone + ' isNew'+isNew); |
| | | if(isNew || isClone){ |
| | | System.debug('caseInfozhj = ' + caseInfo); |
| | | insert caseInfo; |
| | | if(!Test.isRunningTest()){ |
| | | insert caseInfo; |
| | | } |
| | | }else{ |
| | | System.debug('into update'); |
| | | String awsDataId = (String)caseInfo.get('AWS_Data_Id__c'); |
| | | System.debug('awsDataId = ' + awsDataId); |
| | | Case[] cases = [select id from Case where AWS_Data_Id__c =:awsDataId]; |
| | | // String awsDataId = (String)caseInfo.get('AWS_Data_Id__c'); |
| | | // System.debug('awsDataId = ' + awsDataId); |
| | | // Case[] cases = [select id from Case where AWS_Data_Id__c =:awsDataId]; |
| | | System.debug('cases ========================= ' + cases); |
| | | System.debug('Cases[0].id = ' + cases[0].id); |
| | | caseInfo.put('Id',cases[0].id);//For testing; |
| | | update caseInfo; |
| | | if(!Test.isRunningTest()){ |
| | | update caseInfo; |
| | | } |
| | | } |
| | | rid=caseInfo.Id; |
| | | PIHelper.saveTransLog(sobjectTypeValue,(String)caseInfo.get('AWS_Data_Id__c'),rid,transId,caseJson ,status,''); |