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;
      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{
        public String value  { get; set; }
        public String label  { get; set; }

==> HTML :

    <lightning-card title="  Duplicate Form ">
        name="Selected Sales "
        label="  Select Sales"
        source-label="Available Sales"
        selected-label="Selected sales "

            <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>

==> JS:

  @track templateName;

    @track sapid;
    @track nameTem;

    @track err;
    @api recordId;
    listOptions = [];

    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) {

    closeQuickAction() {
        this.dispatchEvent(new CloseActionScreenEvent());

      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 =>  
  • Note this is not free coding service. Also posting whole lot of code which is not relevant to question makes it hard to understand. With that said, what have you tried?
    – metasync
    Jun 3 at 16:19
  • @metasyncc, I tried the code that I posted for the clone() function , but I get as name and sap value undefined . Jun 6 at 14:41


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.