Modification to Services to process Datetime and add error toast
This commit is contained in:
1 parent
a33604b498
commit
26423a7f33
5 files changed
+76
-27
No files matched your search
@@ -28,3 +28,12 @@ package.xml
|
||||
|
||||
# Exclude FieldSets
|
||||
*.fieldSet
|
||||
|
||||
# Exclude Profiles
|
||||
*.profile
|
||||
|
||||
# Exclude Custom Fields
|
||||
*.field
|
||||
|
||||
# Exclude the Opportnity CustomObject
|
||||
Opportunity.object
|
||||
@@ -1,18 +1,44 @@
|
||||
# Salesforce DX Project: Next Steps
|
||||
# Smart Clone - Opportunity Cloner
|
||||
|
||||
Now that you’ve created a Salesforce DX project, what’s next? Here are some documentation resources to get you started.
|
||||
The purpose of the Smart Clone is to provide the user with the functionality to clone an opportunity, but with added
|
||||
benefits.
|
||||
|
||||
## How Do You Plan to Deploy Your Changes?
|
||||
- The ability to select only fields that need to be edited during the cloning
|
||||
- The ability to select fields that must be cleared of their original value
|
||||
- The ability to clone other child objects than just Opportunity Products
|
||||
|
||||
Do you want to deploy a set of changes, or create a self-contained application? Choose a [development model](https://developer.salesforce.com/tools/vscode/en/user-guide/development-models).
|
||||
The Project consists of the following components:
|
||||
| Item | Description |
|
||||
| ---- | ----------- |
|
||||
| OpportunityCloneService | Apex class that contains the Apex functionality |
|
||||
| OpporutnityCloneserviceTest | Code coverage and unit test class |
|
||||
| TestCloneUtility | Utilities used in the Code coverage and unit test class |
|
||||
| SmartCloneChildList custom label | Custom Label used as a setting to store semi-colon separated list of child objects to select from |
|
||||
| opportunityCustomClone | Lightning web component that is the visual interface |
|
||||
| OppCustomCloneAura | Aura Lightning Component that is used to wire to a QuickAction |
|
||||
| Opportunity.SmartClone QuickAction | The QuickAction button to use on the Opportunity Detail Layout |
|
||||
| Opportunity.ClonedFields fieldset | the fieldet used to configure displayable and cleared fields for input |
|
||||
|
||||
## Configure Your Salesforce DX Project
|
||||
### Additional Notes
|
||||
|
||||
The `sfdx-project.json` file contains useful configuration information for your project. See [Salesforce DX Project Configuration](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_config.htm) in the _Salesforce DX Developer Guide_ for details about this file.
|
||||
- This application currently will not support the cloning of a hierarchy of children. This means it is only designed to support
|
||||
the cloning of direct children to the Opportunity, and the Opportunity itself
|
||||
|
||||
## Read All About It
|
||||
## Setup
|
||||
|
||||
- [Salesforce Extensions Documentation](https://developer.salesforce.com/tools/vscode/)
|
||||
- [Salesforce CLI Setup Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm)
|
||||
- [Salesforce DX Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_intro.htm)
|
||||
- [Salesforce CLI Command Reference](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference.htm)
|
||||
### Prerequisites
|
||||
|
||||
- You need to have the Salesforce CLI installed on your system to follow the install directions.
|
||||
|
||||
### Installed Steps
|
||||
|
||||
1. Clone this repository to your local filesystem.
|
||||
2. Navigate to the directory created from the clone.
|
||||
3. Create a 'build' folder in the directory of this cloned repository
|
||||
4. Convert the project into deployable Metadata API format using the following command `sfdx force:source:convert -r ./force-app/main/default -d ./build/unpackaged/`
|
||||
5. Zip the 'unpackaged' directory located in the 'build' folder.
|
||||
6. Deploy the zip file into your instance using the following command `sfdx force:mdapi:deploy -u <yourinstancealias> -f ./build/unpackaged.zip -w 30 --verbose`
|
||||
1. Optionally, you can use the `-l RunLocalTests` option if installing into a production instance separately.
|
||||
7. Once the deployment completes successfully, the components will be installed in your instance.
|
||||
|
||||
### Setup Steps
|
||||
@@ -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]));
|
||||
|
||||
Reference in new issue
Block a user