-1

With this code , I successfully duplicate the object Template__c by creating a new one .

I need to do the same thing for the object Template_Section__c .

Using the same function , and I want to have the new template which is created now with the sections , I want that when I click on the button duplicate template and I switch to the new template created , I find that also the sections of the template is created.

I get just the result of the first insert ( insert newFormTemplate;) I get the new template withe the same information , but I don't get the same thing for the section (the Second insert ) , I only get a new template but for the section I don't get it and also I don't get any error .

Some help please

@AuraEnabled 
  public static void getFormTemplateName(Id TemplateId, string sapValue , Id SectionId){
    Template__c newFormTemplate = new Template__c();
   Template__c formTemplate = [SELECT Id ,Name,RecordTypeId,Template_ID__c FROM Template__c 
                                                  WHERE Id =:TemplateId];
    Sales__c salesOrg = [SELECT Id,Name FROM Sales__c WHERE SAP_Sales_Org_Code__c =: sapValue];                                              
  
    Template_Section__c newSection = new Template_Section__c();

   Template_Section__c TemplateSection = [SELECT Id ,Name,Form_Template__c , Order_Position__c , Section_ID__c FROM C Template_Section__c  WHERE Id =:SectionId];

    newFormTemplate.RecordTypeId = formTemplate.RecordTypeId;
    newFormTemplate.Name = formTemplate.Name;
    newFormTemplate.Form_Template_ID__c = sapValue+'-'+formTemplate.Name;
    newFormTemplate.Sales__c = salesOrg.Id;

    insert newFormTemplate;

    newSection.Name = formTemplateSection.Name;
    newSection.Order_Position__c = formTemplateSection.Order_Position__c;
   newSection.Section_ID__c = sapValue+'-'+ TemplateId +'SECT'+newSection.Order_Position__c;
   insert newSection;   
  }

=> HTML :

 clone(){
        console.log('teste methode0');
        getFormTemplateName({TemplateId: this.recordId, sapValue : this._selected.toString() , })
        console.log('record id is:'+this.recordId);
        console.log('selected is: '+this._selected);
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.recordId,
                objectApiName: 'CORE_Form_Template__c',
                actionName: 'view'
            }
        })
        
        
    .then(result => 
        console.log(result)
        )
        .catch(err =>
             console.log(JSON.stringify(err)))
             console.log('teste methode');
      

            
    }

0

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.