Modification to Services to process Datetime and add error toast

This commit is contained in:
Christopher Gary committed 2021-04-14 21:46:10 -04:00
1 parent a33604b498
commit 26423a7f33
5 files changed
+77 -28

No files matched your search

@@ -32,7 +32,7 @@ public with sharing class OpportunityCloneService {
for(Schema.ChildRelationship childRel:childRelationshipList) {
if(String.isNotBlank(childRel.getRelationshipName())){
Schema.DescribeSObjectResult childObjRes = childRel.getChildSObject().getDescribe();
if(!restrictedRelationshipList.isEmpty()){
if(!restrictedRelationshipList.isEmpty() && restrictedRelationshipList[0] != 'N/A'){
if(restrictedRelationshipList.contains(childObjRes.getName())){
opportunityChildrenMap.put(childRel.getRelationshipName(),childObjRes);
}
@@ -207,7 +207,7 @@ public with sharing class OpportunityCloneService {
returnObj = Date.valueOf(fieldValue);
}
when DATETIME {
returnObj = Datetime.parse(fieldValue);
returnObj = Datetime.valueOf(fieldValue);
}
when ID {
returnObj = Id.valueOf(fieldValue);
@@ -6,17 +6,14 @@
<template for:each={formFields} for:item="formField">
<lightning-input-field key={formField.apiName} field-name={formField.apiName} value={formField.value}></lightning-input-field>
</template>
<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">
<h2 class="slds-text-heading_medium">Child Records to Clone</h2>
<lightning-combobox name="childRelationships" label="Child Relationships" placeholder="Select To Clone"
options={childRelationshipDisplayList} onchange={handleChildRelationshipSelection}></lightning-combobox>
<div class="slds-text-body_small">List of children records to clone:</div>
<lightning-pill-container items={childRelationshipSelectionList} onitemremove={handleChildSelectionRemoval}></lightning-pill-container>
<div class="slds-m-vertical_small">
<lightning-button type="submit" label="Submit"></lightning-button>
</div>
<lightning-button type="submit" label="Submit"></lightning-button>
</lightning-record-edit-form>
</div>
@@ -2,6 +2,7 @@ import { LightningElement, api, wire, track } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import { getRecord } from 'lightning/uiRecordApi';
import { NavigationMixin} from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import OPPORTUNITY_OBJECT from '@salesforce/schema/Opportunity';
import ObtainCloneOpportunityFields from '@salesforce/apex/OpportunityCloneService.ObtainCloneOpportunityFields';
import ObtainChildRelationships from '@salesforce/apex/OpportunityCloneService.ObtainOpporunityChildRelationships';
@@ -17,6 +18,21 @@ export default class OpportunityCustomClone extends NavigationMixin(LightningEle
childRelationshipList;
recordInfo;
childRelationshipDisplayList = [];
toastAttributes = {
"success": {
"title":"Success!",
"message":"Your action was successful",
"variant":"success",
"mode":"dismissable"
},
"error": {
"title":"Error",
"message":"There was an error attempting to execute your request. {0}",
"messageData":[],
"variant":"error",
"mode":"pester"
}
};
@track childRelationshipSelectionList = [];
@wire(getRecord,{recordId:'$recordId',layoutTypes:['Full'],modes:['Edit']})
@@ -27,7 +43,6 @@ export default class OpportunityCustomClone extends NavigationMixin(LightningEle
}
if(data) {
//window.console.log('Original Data: %s',JSON.stringify(data,null,"\t"));
this.recordInfo = data.fields;
}
}
@@ -85,7 +100,6 @@ export default class OpportunityCustomClone extends NavigationMixin(LightningEle
fullSelectedList.push(chosenObj);
}
this.childRelationshipSelectionList = fullSelectedList;
window.console.log('Full Selected List: %s',JSON.stringify(this.childRelationshipSelectionList,null,"\t"));
}
handleChildSelectionRemoval(evt){
@@ -108,11 +122,15 @@ export default class OpportunityCustomClone extends NavigationMixin(LightningEle
window.console.log('Child Relationships Selected: %s',JSON.stringify(childRelList,null,"\t"));
CloneOpportunityWithChildren({'oppId':this.recordId,'newValues':fields,'childRelationshipsToClone':childRelList})
.then((results)=>{
window.console.log('Successful callout. %s',JSON.stringify(results,null,"\t"));
this.sendToOpp(results);
})
.catch((err)=>{
window.console.log('There was an error attempting to clone records.');
let toastInstanceMessage = this.toastAttributes.error;
toastInstanceMessage.messageData.push(err.body.message);
const event = new ShowToastEvent(toastInstanceMessage);
this.dispatchEvent(event);
//window.console.log('There was an error attempting to clone records.');
//window.console.dir(err.body.message);
});
}
sendToOpp(oppId){
@@ -131,7 +149,6 @@ export default class OpportunityCustomClone extends NavigationMixin(LightningEle
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]));