I need some help please .
What I want from this code is that once the button is clicked Clone, we clone the name of the template, and generate Template Name Id which is concatination between the name of the template that I clone and the SAP of the sales org that I selected, after assigning the sales org to the form template that I have created.
Details: the object I want to clone is Form_Template__c and I only want to clone the name, and for the Template Name Id field, it's a concatenation between the name of the template I cloned and the SAP_Sale__c of the Sales__c object that I selected in lightning-dual-listbox .
==> Apex
public with sharing class Clone_form{
@AuraEnabled (cacheable=true)
public static List<SalesOrgWrapper> getSalesOrg(){
List<Sales__c> listSalesOrgs =
[SELECT Id, Name, SAP_Sale__c FROM Sales__c ];
List<SalesOrgWrapper> listOfOptions = new List<SalesOrgWrapper>();
forSales__c salesOrg : listSalesOrgs){
SalesOrgWrapper wrp = new SalesOrgWrapper ( );
wrp.value = salesOrg.SAP_Sales__c;
wrp.label = salesOrg.Name;
listOfOptions.add(wrp);
System.debug(listOfOptions);
}
return listOfOptions;
}
@AuraEnabled (cacheable=true)
public static Form_Template__c getFormTemplateName(Id TemplateId){
Form_Template__c formTemplate = [SELECT Id ,Name FROM Form_Template__c
WHERE Id =:TemplateId];
Form_Template__c eCopy = formTemplate.clone( false, true, false, false );
System.debug('valeur est '+eCopy);
return eCopy;
}
class SalesOrgWrapper{
@AuraEnabled
public String value { get; set; }
@AuraEnabled
public String label { get; set; }
}
}
==> HTML :
<template>
<lightning-card title=" Duplicate Form ">
<lightning-dual-listbox
id="selectOptions"
name="Selected Sales "
label=" Select Sales"
source-label="Available Sales"
selected-label="Selected sales "
options={listOptions}
onchange={getSalesOrg}
>
</lightning-dual-listbox>
<br><br><br>
<div class="slds-modal__footer">
<button class="slds-button slds-button_neutral" aria-label="Cancel and close" type="Cancel" onclick={closeQuickAction}>Cancel</button>
<button class="slds-button slds-button_brand" onclick={clone}>Clone</button>
</div>
</lightning-card>
</template>
==> JS:
@track templateName;
@track sapid;
@track nameTem;
@track err;
@api recordId;
listOptions = [];
@wire(getSalesOrg)
getSalesOrg({ error, data }) {
if (data) {
let option = [];
data.forEach(element => {
console.log('label : '+ JSON.stringify(element));
option.push({ label: element.label, value: element.value });
});
this.listOptions = option;
} else if (error) {
console.log(JSON.stringify(error));
}
}
closeQuickAction() {
this.dispatchEvent(new CloseActionScreenEvent());
}
clone(){
getFormTemplateName({TemplateId : this.recordId})
.then(data => {
console.log('data is '+data)
this.nameTem = data.Name;
console.log('name is'+this.nameTem);
getSalesOrg({selectedId : this.recordId})
.then(data => {
this.sapid = data.SAP_Sales_c ;
console.log('sap est '+this.sapid);
this.templateName = this.sapid+ "-"+ this.nameTem ;
}).catch(err =>
}).catch(err =>
console.log(JSON.stringify(err)))
}
}