Clone Quote with Quote Line Items
- Kriss Lugo
- Apr 28, 2021
- 2 min read
Based on this Idea.

Why you do this to me?! Why Salesforce, Whyyyyy!
Ok; so let's solve this like the adults we are and use Flows! This will be a long ride (maybe I should considere a package for this, what do you think?!) so get some comfortable.
Let's start by creating a Screen flow.
GET RECORD: Get the info from Quote
Filter (Quote.Id = recordId)
recordId is a variable, type Text available for input and output

SCREEN: Let's give the user an option to enter the Quote name
Drag a Text Component to the screen
ASSIGMENT: Let's assign the data
Variable: Var_Quote (Record variable to Quote / Available for inout and output)
I also assigned the new name entered in the screen
** Because there are some fields in my record that trigger other processes I wanted to make sure those did not get copied from the original record; so I added them in the assignment

ASSIGNMENT: Clear the Quote Id (Because we will use this later!)

CREATE RECORD: Create Quote record (clone)

GET RECORD: Get Quote line items
Filter: QuoteId = recordId
All records
Store all fields

SCREEN: This screen it's just to have a pause to give a chance to the flow to generate the cloned record without the related items.
Text Component: Quote Sucessfully Cloned! Click Next to visit the new record.
ASSIGNMENT: Assigned the ClonedId the new Id of the cloned record
ClonedId is a variable, type text and available for input and output

LOOP: To loop over your Quote Line Items
ASSIGNMENT: To assign the related list values
Basically you are copying everything and updating the parent record Id

ASSIGNMENT: To assign record to a collection list
QLIList is a collection record variable

CREATE RECORD: Create all related records from the collection list
Now let's add some screen components to store some errors!
ERROR 1: Text Component
We hit a snag!
We couldn't create the Quote. Please contact your administrator and provide the following information: "AutomationName" | recordId | "StepName" | User.Id
Connect the "Create Quote" element to Error 1
ERROR 2: Text Component
We hit a snag!
We couldn't create the Quote Line Items for this Quote. Please contact your administrator and provide the following information: "AutomationName" | recordId | "StepName" | "ClonedId" | User.Id
Connect the "Create QLI" element to Error 2

Now, let's make sure the user is redirected to the new record:
Open the developer console
Setup (Gear icon) | Developer Console.
Create a new lightning component, click on File | New Lightning Component "NavigateToNewRecord"

Now copy the following code
Component Markup
<aura:component implements="lightning:availableForFlowActions" access="global" >
<aura:attribute name="ClonedId" type="String" access="global"/>
</aura:component>
Client-side Controller
({
invoke : function(component, event, helper) {
var redirectToNewRecord = $A.get( "e.force:navigateToSObject" );
redirectToNewRecord.setParams({
"recordId": component.get( "v.ClonedId" ),
"slideDevName": "detail"
});
redirectToNewRecord.fire();
}
})
Design Resource
<design:component>
<design:attribute name="ClonedId" label="Id of the New Record" />
</design:component>
Save All!
Go back to your flow and add an Action
Find theNavigateToNewRecord componenet
Give it a name
Pass the Id

Yay! You did it, give yourself a high five
Comments