Modifications to lightning component
This commit is contained in:
1 parent
2622f14385
commit
21df2d0bd2
16 files changed
+363
-7
No files matched your search
@@ -1,3 +1,24 @@
|
||||
<template>
|
||||
|
||||
<lightning-card title="Clone Opportunity">
|
||||
<div class="slds-m-horizontal_small slds-grid slds-wrap slds-gutters">
|
||||
<div class="slds-col slds-size_1-of-1">
|
||||
<lightning-record-edit-form object-api-name={formObjectApiName} onsubmit={handleSubmit}>
|
||||
<template for:each={formFields} for:item="formField">
|
||||
<lightning-input-field key={formField.apiName} field-name={formField.apiName} value={formField.value}></lightning-input-field>
|
||||
</template>
|
||||
<lightning-button type="submit" label="Submit"></lightning-button>
|
||||
</lightning-record-edit-form>
|
||||
</div>
|
||||
<div class="slds-col slds-size_1-of-1">
|
||||
<h2 class="slds-text-heading_medium">Child Records to Clone</h2>
|
||||
</div>
|
||||
<div class="slds-col slds-size_1-of-1">
|
||||
<lightning-combobox name="childRelationships" label="Child Relationships" placeholder="Select To Clone"
|
||||
options={childRelationshipDisplayList} onchange={handleChildRelationshipSelection}></lightning-combobox>
|
||||
</div>
|
||||
<div class="slds-col slds-size_1-of-1">
|
||||
<lightning-pill-container items={childRelationshipSelectionList} onitemremove={handleChildSelectionRemoval}></lightning-pill-container>
|
||||
</div>
|
||||
</div>
|
||||
</lightning-card>
|
||||
</template>
|
||||
@@ -1,3 +1,122 @@
|
||||
import { LightningElement } from 'lwc';
|
||||
import { LightningElement, api, wire, track } from 'lwc';
|
||||
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
|
||||
import { getRecord } from 'lightning/uiRecordApi';
|
||||
import OPPORTUNITY_OBJECT from '@salesforce/schema/Opportunity';
|
||||
import ObtainCloneOpportunityFields from '@salesforce/apex/OpportunityCloneService.ObtainCloneOpportunityFields';
|
||||
import ObtainChildRelationships from '@salesforce/apex/OpportunityCloneService.ObtainOpporunityChildRelationships';
|
||||
import CloneOpportunityWithChildren from '@salesforce/apex/OpportunityCloneService.CloneOpportunityWithChildren';
|
||||
|
||||
export default class OpportunityCustomClone extends LightningElement {}
|
||||
export default class OpportunityCustomClone extends LightningElement {
|
||||
@api recordId;
|
||||
|
||||
formObjectApiName;
|
||||
displayedFields;
|
||||
requiredFieldMap;
|
||||
opportunityFields;
|
||||
childRelationshipList;
|
||||
recordInfo;
|
||||
childRelationshipDisplayList = [];
|
||||
@track childRelationshipSelectionList = [];
|
||||
|
||||
@wire(getRecord,{recordId:'$recordId',layoutTypes:['Full'],modes:['Edit']})
|
||||
processRecordInfo({err, data}) {
|
||||
if(err) {
|
||||
window.console.error('There was a problem obtaining Opportunity Record Data');
|
||||
window.console.error(err);
|
||||
}
|
||||
|
||||
if(data) {
|
||||
//window.console.log('Original Data: %s',JSON.stringify(data,null,"\t"));
|
||||
this.recordInfo = data.fields;
|
||||
}
|
||||
}
|
||||
|
||||
@wire(ObtainChildRelationships)
|
||||
processChildRelationships({error, data}) {
|
||||
if(error) {
|
||||
window.console.log('There is an error obtaining Cild Relationships');
|
||||
window.console.error(error);
|
||||
}
|
||||
|
||||
if(data) {
|
||||
var childRelationshipPicklistArray = [];
|
||||
Object.keys(data).forEach(childItem => {
|
||||
childRelationshipPicklistArray.push({'label':data[childItem],'value':childItem});
|
||||
})
|
||||
this.childRelationshipDisplayList = childRelationshipPicklistArray;
|
||||
}
|
||||
}
|
||||
|
||||
@wire(ObtainCloneOpportunityFields,{fieldsetName:'ClonedFields'})
|
||||
processFieldsetInfo({error, data}) {
|
||||
if(error){
|
||||
window.console.error('There is an error obtaining ClonedFields fieldset');
|
||||
window.console.error(error);
|
||||
}
|
||||
if(data){
|
||||
this.displayedFields = Object.keys(data);
|
||||
this.requiredFieldMap = data;
|
||||
}
|
||||
}
|
||||
|
||||
@wire(getObjectInfo,{ objectApiName: OPPORTUNITY_OBJECT })
|
||||
processOpportunityObjectInfo({error, data}) {
|
||||
if(error){
|
||||
window.console.error('There is an error obtaining fields');
|
||||
}
|
||||
if(data){
|
||||
this.formObjectApiName = OPPORTUNITY_OBJECT.objectApiName;
|
||||
this.opportunityFields = data.fields;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @description Handler that executes on selection of child Relationship
|
||||
*/
|
||||
handleChildRelationshipSelection(evt){
|
||||
//find the item that was selected from the distplay list
|
||||
var selectedItem = evt.target.value;
|
||||
let fullSelectedList = this.childRelationshipSelectionList;
|
||||
let displayList = this.childRelationshipDisplayList;
|
||||
let chosenObj = displayList.find( element => element.value === selectedItem);
|
||||
let alreadySelected = fullSelectedList.findIndex(element => element.value === selectedItem);
|
||||
window.console.log('Already Selected Value: %s',alreadySelected);
|
||||
if(chosenObj && alreadySelected < 0){
|
||||
fullSelectedList.push(chosenObj);
|
||||
}
|
||||
this.childRelationshipSelectionList = fullSelectedList;
|
||||
window.console.log('Full Selected List: %s',JSON.stringify(this.childRelationshipSelectionList,null,"\t"));
|
||||
}
|
||||
|
||||
handleChildSelectionRemoval(evt){
|
||||
window.console.log('Item Clicked: %s',evt.detail.index);
|
||||
let fullSelectedList = this.childRelationshipSelectionList;
|
||||
let removedItem = fullSelectedList.splice(evt.detail.index,1);
|
||||
this.childRelationshipSelectionList = fullSelectedList;
|
||||
}
|
||||
/**
|
||||
* @description This will override the submission
|
||||
* @param {*} evt
|
||||
*/
|
||||
handleSubmit(evt){
|
||||
evt.preventDefault();
|
||||
var fields = evt.detail.fields;
|
||||
window.console.log('Fields Submitted: %s',JSON.stringify(fields,null,"\t"));
|
||||
}
|
||||
|
||||
get formFields(){
|
||||
var formFieldsToReturn = [];
|
||||
var fieldRequirementMap = this.requiredFieldMap;
|
||||
if(this.opportunityFields && this.displayedFields && this.recordInfo) {
|
||||
window.console.log('fieldInfo %s: ', JSON.stringify(this.recordInfo,null,"\t"));
|
||||
this.displayedFields.forEach(fieldName => {
|
||||
let fieldItem = fieldRequirementMap[fieldName];
|
||||
let fieldDisplay = JSON.parse(JSON.stringify(this.opportunityFields[fieldName]));
|
||||
if(!fieldItem){
|
||||
fieldDisplay.value = this.recordInfo[fieldName].value;
|
||||
}
|
||||
formFieldsToReturn.push(fieldDisplay);
|
||||
});
|
||||
}
|
||||
return formFieldsToReturn;
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,12 @@
|
||||
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||
<apiVersion>51.0</apiVersion>
|
||||
<isExposed>false</isExposed>
|
||||
<targets>
|
||||
<target>lightning__RecordPage</target>
|
||||
</targets>
|
||||
<targetConfigs>
|
||||
<targetConfig targets="lightning__RecordPage">
|
||||
<property name="recordId" type="String" default="{!recordId]"></property>
|
||||
</targetConfig>
|
||||
</targetConfigs>
|
||||
</LightningComponentBundle>
|
||||
Reference in new issue
Block a user