function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
A.ZaykovA.Zaykov 

Clone opportunity products in Lightning

Hi guys,

My business requirement is to create a quick action which clones opportunity with products in Lightning.

I have created a flow which stores the opportunity products and attach them to the new opportunity.

I was wondering how to pass the Id of the new opportunity to the flow variable "VarT_NewOpportunityId".

Here's the code:
 
<aura:component implements="force:lightningQuickAction,lightning:availableForFlowActions,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
 
     <aura:attribute name="opportunityRecord" type="Object"/>
    <aura:attribute name="clonedOpportunityId" type="String"/>
        <lightning:flow aura:id="flowData"/> 
    <force:recordData aura:id="oppRecord"
                      recordId="{!v.recordId}"
                      layoutType="FULL"
                      targetFields="{!v.opportunityRecord}"/>
   <!--    <aura:handler name="init" value="{!this}" action="{!c.newOpportunity}" /> -->

    <button class="slds-button slds-button_neutral" onclick="{!c.newOpportunity}">Next</button>

</aura:component>
 
({
	newOpportunity : function(component, event, helper) {
		var createOpportunity = $A.get("e.force:createRecord");
		createOpportunity.setParams({
  			"entityApiName": "Opportunity",
    		"defaultFieldValues": {
                'Name' : component.get('v.opportunityRecord.Name'),
                'AccountId' : component.get('v.opportunityRecord.AccountId'),
                'StageName' : component.get('v.opportunityRecord.StageName'),
                'ForecastCategoryName' : component.get('v.opportunityRecord.ForecastCategoryName'),
                'Probability' : component.get('v.opportunityRecord.Probability')
    }
});

	createOpportunity.fire();
     
            var flow = component.find("flowData");
            var inputVariables = [
               {
                  name : "VarT_OldOpportunityId",
                  type : "String",
                  value: component.get("v.opportunityRecord.Id")
               },
                
                {
                    name: "VarT_NewOpportunityId",
                    type : "String",
                    value : "Id of the new opportunity"
                }
               
            ];    
            flow.startFlow("CloneOpportunityProducts", inputVariables);
   
         }
	
})

Any ideas would be much appreciated.

Regards,
Angel
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

Please refer to the below links which might help you further with the above requirement.

https://github.com/sfcure/CloneOpp

https://developer.salesforce.com/forums/?id=9060G000000XhetQAC

https://sfcure.com/2018/06/09/clone-opportunity-with-products-action-on-opportunities-lightning-component/

https://automationchampion.com/tag/clone-opportunity-with-opportunity-products/

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas