In Salesforce, Cloning is the process of creating records with the same details. Salesforce provides the out-of-box feature to clone object records. It’s a way to create a record with similar data and save your precious time. Now I am coming to the point, if some one say’s that they want to clone account with opportunity then you will first think about apex Trigger but no there are other ways this.e Visual Workflow. In this article I will demonstrate how efficiently you develop a deep clone feature for your org.
Business Use Case
Business users at Universal Containers want a way to clone account with opportunity (Only closed won) and set Close date on the new opportunity to today plus 15days. They have only one closed -won opportunity on each account.
Solution for the above business requirement
I took above example only for demo purpose. It may possible your organization maintaining accounts in different ways as mentioned in above business use case. In this blog I will use Visual workflow to solve above business requirement. First of all list down all fields that required to create an account and opportunity, for me to create an account and opportunity it’s required below fields it may vary based upon the custom validation rule
Account | Opportunity |
Name | Name |
Employee | Stage |
Phone | Close Date |
Account Name |
To develop add functionality follow the below instructions
- Click on Name | Setup | App Setup | Create | Workflows & Approvals | Flows
- Click on New Flow, it will open flow canvas for you
- First create a variable with name AccountID to pass account ID, create variable for all fields as shown in below screenshot. In CloseDate variable set default value is {!$Flow.CurrentDate} it means today’s date
- Drag and drop a Record Lookup ( Give the name Account Clone) on the window, to save account field values in variables that you created, as shown in below screenshot
- Likewise drag and drop another Record Lookup ( Give the name Opp Clone) on the window, to save opportunity field values in variables as shown in below screenshot
- The next task is increment CloseDate variable by 15days, to do this drag and drop an Assignment (Give the name Increment date by 15 days) on the window, and add 15 days as shown in below screenshot
- Now we will create account record first, to do this drag and drop another Record Create ( Give the name Create new account) on the window, pass the variable values in the fields and store new account id in a variable in my case it’s NewAccountID as shown in below screenshot
- Final steps create opportunity record. to do this drag and drop another Record Create ( Give the name Create opp) on the window, pass the variable values in the fields. In the AccountId field pass the newly created account id i.e. NewAccountID and select Stage as per your choice, as shown in below screenshot
Finally our flow will look like below screen shot
Save the flow and close the canvas.
It’s time to test this feature
To test this feature you have to create a button on Opportunity to invoke this flow, to do that follow the below instruction
1) Click on Name | Setup | App Setup | Create | Workflow & Approvals | Flow
2) Click on your flow name and go to the detail page and copy URL link
3) Now create a detail page button on Account object and pass Account id to variable AccountID , same as below screen shot
4) Now go to account record that has one opportunity with status “Closed won” and click on the custom button that you created on the last step and see the magic.
Note: – In this demo, I used only a few fields but you can take as many as fields you want but you have to maintain a same number of variables in the flow. You can also add check what happen when the account does not contain any opportunity.
31 thoughts on “Deep Clone through Visual Workflow (Flow)”
sheeba S
I have tried this example but i am getting error as below
ASSIGNMENT: Increment_closedate_15_Days
{!Closedate} Add 15
Result
{!Closedate} = “March 20, 2019”
RECORD CREATE: Create_OPP
Create one Opportunity record where:
AccountId = {!AccountID} (0015A000023heE6)
CloseDate = {!Closedate} (March 20, 2019)
Name = {!OPPName} (Burlington Textiles Weaving Plant Generator)
RecordTypeId = {!RecordID} (0015A000023heE6)
StageName = Prospecting
Result
Failed to create record.
Error Occurred: This error occurred when the flow tried to create records: INVALID_CROSS_REFERENCE_KEY: Record Type ID: this ID value isn’t valid for the user: 0015A000023heE6QAI. You can look up ExceptionCode values in the SOAP API Developer Guide.
Rakesh Gupta
This is beacuse of you’re mapping/passiing incorrect ID for the RecordTypeID field.
sheeba S
i am not sure which id is record id , is that 18 digit id of opportunity field , i am bit confused ,
i tried with 18 digit
RECORD CREATE: Create_OPP
Create one Opportunity record where:
AccountId = {!AccountID} (0015A000023heE6)
CloseDate = {!Closedate} (March 20, 2019)
Name = {!OPPName} (Burlington Textiles Weaving Plant Generator)
RecordTypeId = {!RecordID} (0065A00000lsMiGQAU)
StageName = Prospecting
Result
Failed to create record.
Rakesh Gupta
Not record ID, make sure that you correctly mapped the RecordTyeID first.
Fabian Manzano
I know this variation will not be practical, but just for the sake of learning, how would you ammend the flow to copy all the opportunities as right now for me is only creating 1
Rakesh Gupta
What does means of all the opportunities? Do you want to copy related opportunities of an account?
Junior
I tried to test this flow from the account but I received the following error: An unhandled fault has occurred in this flow.
Rakesh Gupta
Please post the complete error message
Denise Crosby
I can’t get my custom button to show on my Lightning Page. It does how in Salesforce Classic. Is it because using URL custom buttons to pass parameters to standard pages in Salesforce Classic—such as pre-populating fields when creating a record—doesn’t work in Salesforce1 or Lightning Experience?
Rakesh Gupta
I am not sure about Lightning Experience (need time to explorer it) but it should work on Salesforce1.
Sugumar
An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information.
Josh
Is there a way in Flow to copy the record and all populated fields so that when new fields are added the flows will not have to be remapped? Thanks
Rakesh Gupta
Sorry, i am not sure what you are asking. Could you please explain in detail
Ashwin
Hi Rakesh, all of your documentation is very nicely explained. Great work!!!
Rakesh Gupta
Thanks for the kind feedback, Ashwin! 🙂
Riaz
Hi Rakesh Can we Clone a Record from One custom Object to another standard Object when the records get approved
Rakesh Gupta
Yes, it is possible to achieve it with the help of Process Builder. Once record gets approved created a process to copy the data into a custom object
Kelsey
What would it look like if there is more than one Opportunity on the Account? Would this only Clone the first Opportunity
Rakesh Gupta
Correct, you got it right. If you want to clone more than one opportunity then use Fast Elements ( Fast Lookup, Fast Create etc. )
Kelsey
Do you have any information about what the fast lookup/fast create would look like? Use case is to Clone a Location (custom object) and then clone the equipment and products (also custom objects) on that location. Clearly based on the above I can clone the Location based on your example so thank you. Just wondering about what could be done for equipment and products with fast lookup/create and it’s not intuitive for me.
Rakesh Gupta
Record Lookup:-
1) It allows you to save only one record fields value.
2) You can use Variables or SObject Variable to save the record details.
3) One-by-one you have to map the record fields with either Variables or SObject Variable
Fast Lookup:-
1) It allows you to save all the records that, Fast Lookup found after applying the filter criteria.
2) You can use SObject Variable or SObject Collection Variable to save the record details.
3) You don’t have to map the record fields. Here you have just to select the fields whose data you want to save.
Record Create:-
1) It allows you to create one record at a time.
2) You can use Variables or SObject Variable to create a record.
3) One-by-one you have to map the record fields with either Variables or SObject Variable
4) If you use multiple Record Create element in a flow or Record Create element inside Loop element, then it will quickly hit the governor limit
Fast Create:-
1) It allows you to create single or multiple records at a time
2) You can use SObject Variable or SObject Collection Variable to create the record.
3) You don’t have to map the record fields. Here you have just to select the SObject Variable or SObject Collection Variable to create the records.
4) To avoid the governor limits, add the multiple record details into an SObject Collection Variable and refer in a Fast Creat0 element.
Benjamin B
Is it possible to clone attachments using Flow?
For instance, attachments on the opportunity (like a proposal) to a custom object?
Rakesh Gupta
No
Vardaan
Hi Rakesh,
Nice post !
Could we deep clone it one more level? Like if I want to use opportunity lineitem ?Then, how to achieve this scenario for deeper cloning (multiple levels. I mean to say)
Thanks in advance.
Rakesh Gupta
You have to use few more elements in your Flow to clone Opportunity Line Items from an existing Opportunity.
Richa
Rakesh,
I would like to clone cases but only want few fields should be cloned. Is there a way I can do using flows or do i need to create trigger?
Thanks,
Richa
Rakesh Gupta
You can use Flow to achieve it.
Pingback: Getting Started with Process Builder – Part 3 (Clone a record) « Rakesh Gupta's Blog
alliscloud
Hi Rakesh,
I tried cloning following the step you stated in above article but I am receiving message
“Your flow doesn’t have a Start element assigned. “
Rakesh Gupta
Set a start element in your flow. Take a look of this article to know how to set flow’s start element https://developer.salesforce.com/docs/atlas.en-us.salesforce_vpm_guide.meta/salesforce_vpm_guide/vpm_elements_start.htm
Pingback: Rakesh Gupta’s Salesforce Newsletter of the Week – 26th April 2014 « Rakesh Gupta's Blog