force-app/main/default/aura/NewAgencyContact/NewAgencyContactController.js
@@ -18,7 +18,7 @@ record_type_id = pageref.state.recordTypeId } component.set("v.showSpinner", true); helper.CallBackAction(component,'Init',{ helper.CallBackAction(component,'init',{ rid : rid, pid : pid, //rid : component.get('v.recordId'), force-app/main/default/classes/LayoutDescriberHelper.cls
@@ -228,7 +228,8 @@ req.setEndpoint(urlForClassic); req.setHeader('Authorization', 'Bearer ' + UserInfo.getsessionid()); } Http client = new Http(); Http client = new Http(); System.debug('req = ' + req); resp = client.send(req); system.debug('Schema Body:'+JSON.serialize(resp.getBody())); return resp.getBody(); @@ -268,9 +269,9 @@ @AuraEnabled public boolean isPlaceHolder {get;set;} @AuraEnabled public String defaultValue{set;get;} } public static Integer ControllerUtil() { Integer i = 0; return i; } public static Integer ControllerUtil() { Integer i = 0; return i; } } force-app/main/default/classes/LexNewAndEditLeadPIPLController.cls
New file @@ -0,0 +1,222 @@ public with sharing class LexNewAndEditLeadPIPLController { public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); // 字段信息 public static Map<string, SObjectField> fieldMap = new Map<string, SObjectField>(); @AuraEnabled public static ResponseBodyLWC initData2(Id rid, String recordTypeId, String sobjectType) { System.debug('测试 initData2'); return new ResponseBodyLWC('Error', 500, '测试', ''); } @AuraEnabled public static ResponseBodyLWC initData(Id rid, String recordTypeId, String sobjectType) { try { System.debug('rid = ' + rid); System.debug('recordTypeId = ' + recordTypeId); System.debug('sobjectType = ' + sobjectType); fieldMap = schemaMap.get(sobjectType).getDescribe().fields.getMap(); ResponseBodyLWC res = new ResponseBodyLWC(); Map<String, object> data = new Map<String, object>(); res.entity = data; List<Metadata.LayoutSection> layout = null; data.put('recordTypeId', ''); if (String.isEmpty(recordTypeId)) { data.put('recordTypeId', LayoutDescriberHelper.getDefaultRecordType(sobjectType)); recordTypeId = LayoutDescriberHelper.getDefaultRecordType(sobjectType); System.debug('recordTypeId = ' + recordTypeId); } else { data.put('recordTypeId', recordTypeId); } LayoutDescriberHelper.LayoutWrapper LayoutWrapperValue = LayoutDescriberHelper.describeSectionWithFieldsWrapper(recordTypeId,'Lead','lightning'); List<LayoutDescriberHelper.LayoutSection> layoutSections = LayoutWrapperValue.layoutSections; data.put('layout', Json.serialize(layoutSections)); //编辑 if(!String.isBlank(rid)){ //获取对应对象的字段 List<Sobject> lso = Database.query('select id from RecordType where SobjectType = :sobjectType'); string sql = 'select Contact_Name__r.LastName,Contact_Name__r.AWS_Data_Id__c,Hospital_Name__r.Id'; DescribeSObjectResult objectType = rid.getSobjectType().getDescribe(); List<String> objectFields = new List<String>(objectType.fields.getMap().keySet()); sql += ', ' + String.join(objectFields, ',') +' from '+sobjectType+' where id =\''+rid+'\' limit 1'; System.debug('sql = ' + sql); Sobject leadData = Database.query(sql); if(leadData == null){ return new ResponseBodyLWC('Error',500, 'id不存在', ''); } data.put('recordTypeId', (String)leadData.get('RecordTypeId')); data.put('AWSDataId', (String)leadData.get('AWS_Data_Id__c')); //获取值 System.debug('leadData = ' + JSON.serialize(leadData)); data.put('data', leadData); } //获取PI字段 PIHelper.PIIntegration piIntegration = PIHelper.getPIIntegrationInfo(sobjectType); Map<String, String> AWSToSobjectNonEncryptedMap = new Map<String, String>(); List<String> AWSToSobjectNonEncryptedMapKeySet = new List<String>(); for (PI_Field_Policy_Detail__c PIDetail : piIntegration.PIDetails) { AWSToSobjectNonEncryptedMap.put(PIDetail.AWS_Field_API__c, PIDetail.SF_Field_API_Name__c); AWSToSobjectNonEncryptedMapKeySet.add(PIDetail.AWS_Field_API__c); } data.put('AWSToSobjectNonEncryptedMap', AWSToSobjectNonEncryptedMap); data.put('AWSToSobjectNonEncryptedMapKeySet', AWSToSobjectNonEncryptedMapKeySet); data.put('staticResource', Json.serialize(PIHelper.getPIIntegrationInfo(sobjectType))); data.put('staticResourceContact', Json.serialize(PIHelper.getPIIntegrationInfo('Contact'))); res.status = 'Success'; res.code = 200; res.msg = ''; return res; } catch (Exception e) { System.debug('error = ' + e.getMessage() + ' line = ' + e.getLineNumber()); return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), ''); } } @AuraEnabled public static ResponseBodyLWC queryAccount(String accountTypes, String accountId) { ResponseBodyLWC res = new ResponseBodyLWC(); Map<String, object> data = new Map<String, object>(); res.entity = data; System.debug('accountType = ' + accountTypes); System.debug('accountId = ' + accountId); try { List<Object> types = (List<Object>) JSON.deserializeUntyped(accountTypes); System.debug('types=' + types); String soql = 'select Id,Name,'; for (Object t : types) { soql += (String) t + ','; } soql = soql.substring(0, soql.length() - 1); soql += ' from Account where id=\'' + accountId + '\''; System.debug('soql=' + soql); Sobject account = new Account(); if (!Test.isRunningTest()) { account = Database.query(soql); } else { account.put('Id', '000000000000000'); } Map<String, Map<String, String>> m = new Map<String, Map<String, String>>(); System.debug('account=' + account); for (Object ty : types) { String t = (String) ty; if (account.get(t) != null || Test.isRunningTest()) { Sobject acc = new Account(); if (Test.isRunningTest()) { acc.put('Id', '000000000000000'); acc.put('Name', 'Name'); } else { acc = Database.query('select Id,Name from Account where id=\'' + account.get(t) + '\''); } Map<String, String> n = new Map<String, String>(); n.put('Id', (String) acc.get('Id')); n.put('Name', (String) acc.get('Name')); m.put(t, n); } } System.debug('m=' + m); data.put('m', m); data.put('account', account); res.status = 'Success'; res.code = 200; res.msg = ''; return res; } catch (Exception e) { return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), ''); } } @AuraEnabled public static ResponseBodyLWC searchContactInit(String accountId, String searchKeyWord) { ResponseBodyLWC res = new ResponseBodyLWC(); Map<String, object> data = new Map<String, object>(); res.entity = data; System.debug('accountId = ' + accountId); System.debug('searchKeyWord = ' + searchKeyWord); try { List<Contact> conList = new List<Contact>(); List<Contact> noPIContactList = new List<Contact>(); if (checkNullString(accountId) && checkNullString(searchKeyWord)) { conList = new List<Contact>(); } else { if (checkNullString(accountId)) { conList = new List<Contact>(); } else { //2022-5-12 yjk 将科室匹配改为医院匹配查询联系人 statt Account act = [SELECT id, Hospital__c FROM Account WHERE id = :accountId]; conList = new List<Contact>( [ SELECT Id, AWS_Data_Id__c, Account.Name FROM Contact WHERE Account.Hospital__c = :act.Hospital__c AND AWS_Data_Id__c != '' ] ); noPIContactList = AWSServiceTool.getNoPIContact(searchKeyWord, accountId); //2022-5-12 yjk 将科室匹配改为医院匹配查询联系人 end } } Map<String, Contact> awsIdToContactMap = new Map<String, Contact>(); List<String> conAWSIds = new List<String>(); for (Contact con : conList) { conAWSIds.add(con.AWS_Data_Id__c); awsIdToContactMap.put(con.AWS_Data_Id__c, con); } data.put('awsIdToContactMap', awsIdToContactMap); data.put('conAWSIds', conAWSIds); data.put('noPIContactList', noPIContactList); data.put('contactStaticResource', JSON.serialize(PIHelper.getPIIntegrationInfo('Contact'))); res.status = 'Success'; res.code = 200; res.msg = ''; return res; } catch (Exception e) { return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), ''); } } public static Boolean checkNullString(String inputString) { if (String.isEmpty(inputString) || String.isBlank(inputString)) { return true; } return false; } /** *@description 转换layout *@param sections 默认metalayout *@return List<Metadata.LayoutSection> 标准metalayout */ public static List<Metadata.LayoutSection> reviseMetaLayouts(List<Metadata.LayoutSection> sections) { List<Metadata.LayoutSection> result = new List<Metadata.LayoutSection>(); if (sections == null) { return null; } for (Metadata.LayoutSection s : sections) { Metadata.LayoutSection section = new Metadata.LayoutSection(); section.customLabel = s.customLabel; section.detailHeading = s.detailHeading; section.editHeading = s.editHeading; section.label = s.label; section.style = s.style; result.add(section); for (Metadata.LayoutColumn c : s.layoutColumns) { if (c.layoutItems == null) { break; } Metadata.LayoutColumn col = new Metadata.LayoutColumn(); col.reserved = col.reserved; section.layoutColumns.add(col); for (Metadata.layoutItem item : c.layoutItems) { if (!fieldMap.containsKey(item.field) || !isUpdateable(fieldMap.get(item.field).getDescribe())) { System.debug(item.field); continue; } col.layoutItems.add(item); } } } return result; } private static Boolean isUpdateable(Schema.DescribeFieldResult dfr) { return (new List<String>{ 'Id', 'Name' }).contains(dfr.getName()) || dfr.isUpdateable(); } } force-app/main/default/classes/LexNewAndEditLeadPIPLController.cls-meta.xml
New file @@ -0,0 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>57.0</apiVersion> <status>Active</status> </ApexClass> force-app/main/default/classes/NewAgencyContactController.cls
@@ -3,7 +3,8 @@ static string sobjectType = 'Agency_Contact__c'; @AuraEnabled public static ControllerResponse Init(string rid,Id pid, string record_type_id){ public static ControllerResponse init(string rid,Id pid, string record_type_id){ system.debug('Debug lighting'); system.debug('rid='+rid+',length='+(rid==null?'null':rid.length()+'')); system.debug('record_type_id='+record_type_id+',length='+(record_type_id==null?'null':record_type_id.length()+'')); force-app/main/default/classes/TestUserExample.cls
New file @@ -0,0 +1,49 @@ @isTest public with sharing class TestUserExample { @isTest static void itWorks() { System.runAs(new User(Id = UserInfo.getUserId())){ createUser(); } User user = [SELECT Id FROM User WHERE UserName LIKE 'admin%' LIMIT 1]; //query user // //createAccount(); } private static void createAccount(){ String random = String.valueof(DateTime.now().getTime()); Account acc = new Account(Name = random); acc.CurrencyIsoCode = 'USD'; acc.BillingCity = 'New York'; acc.BillingCountry = 'United States'; acc.BillingState = 'New York'; acc.BillingStreet = 'abc 1234'; acc.Website = 'www.google.com'; insert ACC; } private static void createUser(){ String random = String.valueof(DateTime.now().getTime()); Profile profile = [SELECT Id FROM Profile WHERE Name='系统管理员']; User user = new User(); user.Email = 'random@random.com'+random; user.UserName = 'admin@random.com'+random; user.LastName = 'random'+random; user.Alias = 'random'; user.ProfileId = profile.Id; user.EmailEncodingKey='UTF-8'; user.LanguageLocaleKey='en_US'; user.LocaleSidKey='en_US'; user.TimeZoneSidKey = 'America/Los_Angeles'; insert user; } } force-app/main/default/classes/TestUserExample.cls-meta.xml
New file @@ -0,0 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>57.0</apiVersion> <status>Active</status> </ApexClass> force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.html
New file @@ -0,0 +1,75 @@ <!-- sldsValidatorIgnore --> <!-- sldsValidatorIgnore --> <template> <template if:true={isShowSpinner}> <lightning-spinner size="large" alternative-text="Loading"></lightning-spinner> </template> <!-- 查询客户名 --> <template if:true={isShowSearchAccount}> <c-lex-search-lookup-l-w-c title="客户名" search-name-label="客户名" onclose={closeHospitalNameModal} onselectcontact={handleSelectContact} account-id={hospitalId}></c-lex-search-lookup-l-w-c> </template> <!-- 展示 --> <lightning-quick-action-panel header={title}> <lightning-record-edit-form object-api-name="Lead" record-type-id={recordTypeId} record-id={recordId} onsubmit={handleSubmit} onsuccess={handleSuccess} onerror={handleError}> <template for:each={layout} for:item="layoutSection"> <template if:true={layoutSection.useHeader}> <lightning-accordion class="greyyyy" active-section-name={sectionName} allow-multiple-sections-open key={layoutSection.name}> <lightning-accordion-section name={layoutSection.name} label={layoutSection.name}> <lightning-layout multiple-rows="true"> <template for:each={layoutSection.layoutFields} for:item="layoutField"> <lightning-layout-item class="hehe-layoutItem" size="6" key={layoutField.fieldAPI}> <template if:false={layoutField.isModify}> <lightning-input-field field-name={layoutField.fieldAPI} value={layoutField.value} required={layoutField.isRequired} data-field={layoutField.fieldAPI} disabled={layoutField.isDisable} onchange={dataChange}> </lightning-input-field> </template> <template if:true={layoutField.isModify}> <template if:true={layoutField.isShowIcon}> <div class="slds-form-element__control slds-input-has-icon slds-input-has-icon_right"> <lightning-icon size="x-small" class="iconMargin slds-icon slds-input__icon slds-input__icon_right slds-icon-text-default" icon-name="utility:search"></lightning-icon> <lightning-input label={layoutField.fieldLabel} value={layoutField.value} required={layoutField.isRequired} data-field={layoutField.fieldAPI} disabled={layoutField.isDisable} variant="label-inline" onchange={dataChange} onclick={searchHospitalNameModal}> </lightning-input> </div> </template> <template if:false={layoutField.isShowIcon}> <lightning-input label={layoutField.fieldLabel} value={layoutField.value} required={layoutField.isRequired} data-field={layoutField.fieldAPI} disabled={layoutField.isDisable} variant="label-inline" onchange={dataChange} onclick={searchHospitalNameModal}> </lightning-input> </template> </template> </lightning-layout-item> </template> </lightning-layout> </lightning-accordion-section> </lightning-accordion> </template> </template> <div class="slds-text-align_center"> <lightning-button label="保存" type="submit" onsubmit={handleSubmit} class="slds-m-right_x-small"></lightning-button> <lightning-button label="取消" onclick={cancel} class="slds-m-right_x-small"></lightning-button> </div> </lightning-record-edit-form> </lightning-quick-action-panel> </template> force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.js
New file @@ -0,0 +1,525 @@ import { LightningElement, api, track, wire } from 'lwc'; import { CurrentPageReference } from 'lightning/navigation'; import initData from '@salesforce/apex/LexNewAndEditLeadPIPLController.initData'; import queryAccount from '@salesforce/apex/LexNewAndEditLeadPIPLController.queryAccount'; import { NavigationMixin } from 'lightning/navigation'; import { AWSService } from 'c/piUtils'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; export default class LexNewAndEditLeadPIPL extends NavigationMixin(LightningElement) { sobjectType = 'Lead'; @api recordId; @wire(CurrentPageReference) pageRef; @track recordData = {}; @track title; @track recordTypeId = ''; @track isShowSpinner = true; @track layout = []; @track staticResource; @track staticResourceContact; @track piFieldsMap; @track abstractData = ''; @track data = {}; @track piplData = {}; @track isNewMode = false; @track isCloneMode = false; @track isEditMode = false; @track sectionName = []; @track AWSToSobjectMap = {}; @track AWSDataId = ''; @track contactAWSDataId = ''; @track txId = ''; @track isShowSearchAccount = false; @track hospitalId = ''; @track contactId = ''; AWSService; //姓名 //@track lastName = ''; @track modifyObj = {}; modifyArray = ['LastName', 'Hospital_Name__c']; connectedCallback() { console.log('enter connectedCallback'); this.AWSService = new AWSService(); if (!this.recordId || this.isCloneMode) { this.title = '新建意向'; this.isNewMode = true; } if(this.recordId){ this.title = '编辑意向'; this.isEditMode = true; } if (this.pageRef && this.pageRef.state) { this.recordTypeId = this.pageRef.state.recordTypeId; console.log('this.recordTypeId = ' + this.recordTypeId); } console.log('recordId = ' + this.recordId + ' pid = ' + this.pid + ' recordTypeId = ' + this.recordTypeId + ' sobjectType = ' + this.sobjectType); initData({ rid: this.recordId, recordTypeId: this.recordTypeId, sobjectType: this.sobjectType }).then((r) => { r = JSON.parse(JSON.stringify(r)); if (r.status == 'Success') { let layout = JSON.parse(r.entity.layout); console.log('layout = ' + JSON.stringify(layout)); this.layout = layout; this.recordData = r.entity.data; console.log('this.recordData = ' + JSON.stringify(this.recordData)); this.AWSDataId = r.entity.AWSDataId; for (var s of layout) { this.sectionName.push(s.name); for (var c of s.layoutFields) { c['isModify'] = false; c['isDisable'] = !c.editableField; //名字,只留LastName if(c['fieldAPI'] == 'Name') { c.fieldAPI = 'LastName'; c.fieldLabel = '姓名' c['isModify'] = true; if(this.isEditMode){ c['value'] = this.recordData.LastName } } //客户人员名,因为要进行联动和解密所以变为普通input,自己控制值 if(c['fieldAPI'] == 'Contact_Name__c'){ c['isModify'] = true; c['isShowIcon'] = true; if(this.isEditMode){ c['value'] = this.recordData.Contact_Name__r == null ? '' : this.recordData.Contact_Name__r.LastName; this.contactId = this.recordData.Contact_Name__c == null ? '' : this.recordData.Contact_Name__c; this.contactAWSDataId = this.recordData.Contact_Name__r == null ? '' : this.recordData.Contact_Name__r.AWS_Data_Id__c; } } if(c['fieldAPI'] == 'Hospital_Name__c' && this.isEditMode){ this.hospitalId = this.recordData.Hospital_Name__r == null ? '' : this.recordData.Hospital_Name__r.Id; } } } this.AWSToSobjectMap = JSON.parse(JSON.stringify(r.entity.AWSToSobjectNonEncryptedMap)); this.staticResource = JSON.parse(r.entity.staticResource); this.staticResourceContact = JSON.parse(r.entity.staticResourceContact); this.recordTypeId = r.entity.recordTypeId; //编辑 if(this.isEditMode){ //解密客户人员 this.queryContactName(); //解密意向的加密字段 this.queryLeadFromAWSIFS(); } this.isShowSpinner = false; } else { this.isShowSpinner = false; this.showToast('Error', r.Msg); } }) } //解密客户人员 queryContactName(){ var that = this; this.AWSService.query(this.staticResourceContact.queryUrl,this.contactAWSDataId,function(data){ console.log('data = ' + JSON.stringify(data)); if (data.object) { for (var s of that.layout) { for (var c of s.layoutFields) { if(c['fieldAPI'] == 'Contact_Name__c'){ c['value'] = data.object.lastName; } } } } },this.staticResourceContact.token) } //解密意向的加密字段 queryLeadFromAWSIFS(){ var that = this; debugger this.AWSService.query(this.staticResource.queryUrl,this.AWSDataId,function(data){ console.log('queryLeadFromAWSIFS data = ' + JSON.stringify(data)); if (data.object) { for (var s of that.layout) { for (var c of s.layoutFields) { for (let f in that.AWSToSobjectMap) { debugger if (data.object.hasOwnProperty(f) && c['fieldAPI'] == that.AWSToSobjectMap[f]) { c['value'] = data.object[f] == null ? '' : data.object[f]; if(c['fieldAPI'] == 'LastName'){ that.modifyObj['LastName'] = data.object[f] == null ? '' : data.object[f]; } } } // if(c['fieldAPI'] == 'LastName'){ // console.log('data.object.lastName = ' + data.object.lastName); // c['value'] = data.object.lastName == null ? '' : data.object.lastName; // that.modifyObj['LastName'] = data.object.lastName == null ? '' : data.object.lastName; // console.log('this.modifyObj[LastName] = ' + that.modifyObj['LastName']); // } // if(c['fieldAPI'] == 'Phone'){ // console.log('data.object.phone = ' + data.object.phone); // c['value'] = data.object.phone == null ? '' : data.object.phone; // } // if(c['fieldAPI'] == 'Email'){ // console.log('data.object.email = ' + data.object.email); // c['value'] = data.object.email == null ? '' : data.object.email; // } } } } },this.staticResource.token) } //取消 cancel() { console.log('cancel'); window.history.back(); } //change事件 dataChange(event) { let fieldName = event.target.getAttribute("data-field"); let value = event.detail.value; console.log("fieldName = " + fieldName + " value = " + event.detail.value); for (var s of this.layout) { for (var c of s.layoutFields) { if(c.fieldAPI == fieldName){ console.log('c.fieldAPI = ' + c.fieldAPI); c['value'] = value; } } } if(this.modifyArray.indexOf(fieldName) != -1){ switch(fieldName){ case "LastName": this.modifyObj[fieldName] = value; break; case "Hospital_Name__c": //需要给战略科室分类和公司赋值 if(value != "000000000000000" && value != ''){ let ls = ['Department_Class__c']; this.hospitalId = value; this.setVlookup(ls,value+''); }else{ //清空战略科室分类 this.clearVlookup(); } break; } } } //战略科室分类和公司赋值 setVlookup(ls,hospitalId){ this.isShowSpinner = true; console.log('ls = ' + JSON.stringify(ls)); console.log('hospitalId = ' + hospitalId); queryAccount({ accountTypes : JSON.stringify(ls), accountId : hospitalId }).then((r) => { r = JSON.parse(JSON.stringify(r)); console.log('r = ' + JSON.stringify(r)); if (r.status == 'Success') { console.log('queryAccount success'); for (var s of this.layout) { for (var c of s.layoutFields) { if(c['fieldAPI'] == 'Department_Class__c'){ console.log('m = ' + JSON.stringify(r.entity.m)) if(JSON.stringify(r.entity.m) != '{}'){ c['value'] = r.entity.m.Department_Class__c.Id; } } if(c['fieldAPI'] == 'Company'){ c['value'] = r.entity.account.Name; } } } //1.5秒后将会调用执行remind()函数 var that = this; setTimeout(function() { that.isShowSpinner = false; }, 1500); //this.isShowSpinner = false; } else { this.showToast('Error', r.Msg); } }) } //清空战略科室分类 clearVlookup(){ console.log('clearVlookup') for (var s of this.layout) { for (var c of s.layoutFields) { if(c['fieldAPI'] == 'Department_Class__c'){ c['value'] ='' } } } //this.layout = [...this.layout]; } //提交保存 handleSubmit(event) { this.isShowSpinner = true; //1. Get Sobject Information from Form console.log('handleSubmit'); event.preventDefault(); const fields = event.detail.fields; console.log('this.modifyObj = ' + JSON.stringify(this.modifyObj)); Object.assign(fields, this.modifyObj); fields['Contact_Name__c'] = this.contactId; console.log('fields = ' + JSON.stringify(fields)); //2. select cannot actively select redaction option let validationResultMessage = this.validateFieldValueFormate(fields); console.log(validationResultMessage); if (validationResultMessage) { this.showToast('Error', validationResultMessage); return } //3. Check Required Field let checkRequiredFieldMsgResult = this.checkRequiredFieldMsg(fields); console.log('checkRequiredFieldMsgResult = ' + checkRequiredFieldMsgResult); if (checkRequiredFieldMsgResult != '') { this.showToast('Error', checkRequiredFieldMsgResult + '需要进行填写'); return } //4. Prepare the payload for New PI API To AWS - To Do let payloadForNewPI = this.getPIPayload(fields); console.log('payloadForNewPI = ' + payloadForNewPI); //5. PI To AWS //新建 debugger if(this.isNewMode){ this.NewPIToAWS(payloadForNewPI,fields); } //编辑 if(this.isEditMode){ this.UpdatePIToAWS(payloadForNewPI,fields); } } //提交保存ToAWS NewPIToAWS(payloadForNewPI,fields){ this.AWSService.post(this.staticResource.newUrl, payloadForNewPI, (result) => { if (result && result.object) { console.log('result = ' + JSON.stringify(result)); for (let f in this.AWSToSobjectMap) { if (result.object[0].hasOwnProperty(f)) { fields[this.AWSToSobjectMap[f]] = result.object[0][f]; console.log('this.AWSToSobjectMap[f] = ' + this.AWSToSobjectMap[f]); console.log('fields[this.AWSToSobjectMap[f]] = ' + fields[this.AWSToSobjectMap[f]]); } else { console.log(f + 'is not in result.object[0]'); } } if (this.isNewMode) { fields['AWS_Data_Id__c'] = result.object[0].dataId; } else { //更新 } this.txId = result.txId; console.log('this.txId = ' + this.txId); console.log('PI After fields = ' + JSON.stringify(fields)); if(fields.RecordTypeId){ console.log('length = ' + JSON.stringify(fields.RecordTypeId.length)); fields['RecordTypeId'] = fields.RecordTypeId.substring(1, fields.RecordTypeId.length - 1); console.log('RecordTypeId = ' + JSON.stringify(fields['RecordTypeId'])); } //保存到后端 this.template.querySelector('lightning-record-edit-form').submit(fields); } else { console.log('result = ' + JSON.stringify(result)); } }, this.staticResource.token); } //编辑保存ToAWS UpdatePIToAWS(payloadForNewPI,fields){ let obj = JSON.parse(payloadForNewPI); obj[0].dataId = this.AWSDataId; let payloadForNewPIJson = JSON.stringify(obj); this.AWSService.post(this.staticResource.updateUrl, payloadForNewPIJson,(result) =>{ if (result && result.object) { console.log('result = ' + JSON.stringify(result)); for (let f in this.AWSToSobjectMap) { if (result.object[0].hasOwnProperty(f)) { fields[this.AWSToSobjectMap[f]] = result.object[0][f]; console.log('this.AWSToSobjectMap[f] = ' + this.AWSToSobjectMap[f]); console.log('fields[this.AWSToSobjectMap[f]] = ' + fields[this.AWSToSobjectMap[f]]); } else { console.log(f + 'is not in result.object[0]'); } } if (this.isNewMode) { fields['AWS_Data_Id__c'] = result.object[0].dataId; } else { //更新 fields['AWS_Data_Id__c'] = this.AWSDataId; } this.txId = result.txId; console.log('this.txId = ' + this.txId); console.log('PI After fields = ' + JSON.stringify(fields)); if (fields.RecordTypeId) { console.log('length = ' + JSON.stringify(fields.RecordTypeId.length)); fields['RecordTypeId'] = fields.RecordTypeId.substring(1, fields.RecordTypeId.length - 1); console.log('RecordTypeId = ' + JSON.stringify(fields['RecordTypeId'])); } //保存到后端 console.log('update submit = ' + JSON.stringify(fields)); this.template.querySelector('lightning-record-edit-form').submit(fields); } else { console.log('result = ' + JSON.stringify(result)); } } ,this.staticResource.token); } //提交保存成功 handleSuccess(event) { let updatedRecord = event.detail.id; console.log('onsuccess: ', updatedRecord); //成功之后确认事物 console.log('confirmTrans'); let that = this; this.AWSService.confirm(true,updatedRecord,this.txId,this.staticResource.token,this.staticResource.transactionUrl,function(result){ console.log('result = ' + JSON.stringify(result)) that.showToast('Success','保存成功'); console.log('updatedRecord = ' + updatedRecord) that[NavigationMixin.Navigate]({ type: 'standard__recordPage', attributes: { actionName: "view", recordId: updatedRecord, objectApiName: that.sobjectType } }); }); } //提交保存失败 handleError(event) { event.preventDefault(); event.stopImmediatePropagation(); this.showToast("Error", event.detail.detail); this.AWSService.confirm(false,'',this.txId,this.staticResource.token,this.staticResource.transactionUrl,function(result){ console.log('result = ' + JSON.stringify(result)) }); } //验证字段 validateFieldValueFormate() { let error_msg = ''; let b = false; for(var key in fields){ if(fields[key] == "*****") b = true; } if(b) error_msg = '下拉框不能主动选择密文选项'; return error_msg; } //验证required字段需要进行填写 checkRequiredFieldMsg(fields){ let msg = ''; for (var s of this.layout) { for (var c of s.layoutFields) { if(c.isRequired && c.editableField && (fields[c.fieldAPI] == null || fields[c.fieldAPI] == '')){ msg += ';' + c.fieldLabel; } } } msg = msg.substring(1); return msg; } //获取PI字段 getPIPayload(sobjJsonLwc) { console.log() let leadPayloadList = []; let leadPIData = {}; for (let f in this.AWSToSobjectMap) { if (sobjJsonLwc.hasOwnProperty(this.AWSToSobjectMap[f])) { leadPIData[f] = sobjJsonLwc[this.AWSToSobjectMap[f]] } else { console.log(this.AWSToSobjectMap[f] + 'is not in sobjJsonLwc'); } } leadPIData.medicalStaffFullName = leadPIData.lastName; leadPIData.sfRecordId = ''; console.log('Sobject PI Data x :' + leadPIData); leadPayloadList.push(leadPIData); console.log('leadPayloadList = ' + JSON.stringify(leadPayloadList)); return JSON.stringify(leadPayloadList); } //查询客户人员根据医院 searchHospitalNameModal(event){ let fieldName = event.target.getAttribute("data-field"); if(fieldName == 'Contact_Name__c'){ if(this.hospitalId == "000000000000000" || this.hospitalId == ''){ this.showToast('Error','请先选择医院名'); return } this.isShowSearchAccount = true; } } //选择客户人员后进行赋值 handleSelectContact(event){ this.isShowSpinner = true; console.log('enter handleSelectContact '); const selectContact = event.detail; console.log('selectContact = ' + JSON.stringify(selectContact)) for (var s of this.layout) { for (var c of s.layoutFields) { if(c['fieldAPI'] == 'Contact_Name__c'){ c['value'] = selectContact.data.medicalStaffFullName; this.contactId = selectContact.data.sfRecordId; console.log('this.contactId = ' + this.contactId); console.log('selectContact.data.sfRecordId = ' + selectContact.data.sfRecordId); console.log('c[value] = ' + c['value']); } if(c['fieldAPI'] == 'LastName'){ c['value'] = selectContact.data.medicalStaffFullName; this.modifyObj['LastName'] = selectContact.data.medicalStaffFullName; console.log('c[value] = ' + c['value']); } } } this.layout = [...this.layout]; this.isShowSpinner = false; this.closeHospitalNameModal(); } //关闭客户人员根据医院模态框 closeHospitalNameModal(){ this.isShowSearchAccount = false; } //显示信息 showToast(type, msg) { this.isShowSpinner = false; const event = new ShowToastEvent({ title: type, variant: type, message: msg }); this.dispatchEvent(event); } } force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.js-meta.xml
New file @@ -0,0 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>57.0</apiVersion> <isExposed>true</isExposed> <targets> <target>lightning__AppPage</target> <target>lightning__RecordPage</target> <target>lightning__HomePage</target> <target>lightning__RecordAction</target> <target>lightningCommunity__Page_Layout</target> </targets> </LightningComponentBundle> force-app/main/default/pages/NewAndEditLead.page
@@ -1,9 +1,10 @@ <apex:page lightningStylesheets="true" standardController="Lead" extensions="NewAndEditLeadController" id="page"> <apex:page standardController="Lead" extensions="NewAndEditLeadController" id="page" lightningStyleSheets="true"> <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}" /> <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" /> <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}" /> <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}" /> <apex:includeScript value="{!URLFOR($Resource.connection20)}"/> <apex:slds /> <style> .disabledbutton { pointer-events: none;