+ Start a Discussion
tengeltengel 

Deep Clone Opportunity with Products via Visual Workflow?

Here is the use case: Sales person doesn't close the sale this year :(   They click a button on Opportunity page layout which launches a loss analysis flow where we capture useful information like who we lost it to, why we lost it, notes about how this went down, etc.

 

One screen asks the user if they want to create a follow-up Opportunity for next year. If they choose "Yes," I'd ideally clone the entire Opportunity record with all of its products and just adjust things like Stage and Close Date using the flow.

 

I know I can't achieve this without an Apex plugin, and I was wondering if anyone out there has one built that can handle this, or can assist me in getting something like it developed. I am not an Apex developer, but I can find my way around some code if I have something to start playing with.

 

Thanks for any guidance.

Best Answer chosen by Admin (Salesforce Developers) 
RajaramRajaram
You are effectively doing an infinite loop. You need a decision after the lookup which checks if the lookup returned any records. Only when you do should you enter the loop by oh should exit the loop otherwise.

The decision criteria is
{!mylookupelement} equals {$GlobalConstant.true}

Hope this helps.

Raja

All Answers

RajaramRajaram
It should be possible. You have a custom button on the opty called Deep Clone which queries the existing opty and opty lines and creates them in the flow.
You can loop through the lines and create a new line for the opty in a flow.
tengeltengel

Thanks, Rajaram, I'm sort of following but don't really know how to get started. Any chance you can share some sample code? Right now, the button that launches the flow passes the Opportunity ID into the flow. It's just a matter of how I can go about looping through and cllecting each line item to reparent to the newly cloned record in the flow.

RajaramRajaram
You need to do the following
1. Create a loop in your flow which queries the opty lines for the opty ID you passed
2. To ensure you get to process all the lines, you have to create a custom field on the opty line and use that in the filter criteria.
For example, create a field called "processed" which is a checkbox and use that in the filer. so your filter for the record lookup will be optyID = {!myOptyID} and processed equals false
3. In the loop, update that line and set the processed to true. THis will ensure the line will not be queried again in the loop.

Hope this helps..

Raja
tengeltengel

Ok, I get it now.

 

So I tried creating the loop as you described...I use a record lookup to find Line Items where opportunity id = {!myopptyid} and Processed__c = false and store the line item ID in a variable called oli_id. Then, we go to a record update step which updates Processed__c to True where Id = {!oli_id}. Then I send the flow back into the line item lookup. Here's in image of the loop: Flow Loop Error

 

When I send the flow out of the loop, there is a FAULT notification between step connectors. When I try to run a test, I receive the following error:

 

Limit Exceeded
You or your organization has exceeded the maximum limit for this feature.

 

Any idea what's going on here? I'm guessing it has something to do with the oli_id variable?

RajaramRajaram
You are effectively doing an infinite loop. You need a decision after the lookup which checks if the lookup returned any records. Only when you do should you enter the loop by oh should exit the loop otherwise.

The decision criteria is
{!mylookupelement} equals {$GlobalConstant.true}

Hope this helps.

Raja
This was selected as the best answer
tengeltengel

Brilliant! Raja, thank you for your input, this has helped me tremendously. You are a wizard!

RajaramRajaram
Ha.. you are too kind!
Happy to help..
Happy flowing!
Ashley SistiAshley Sisti
Do you possibly have a screenshot of your finished product? I need to do something very similar and am lost on how to collect all the fields I need to clone and bring over from the Opportunity and OLIs. Would I do it using the <interview> parameter tags (if I've got the flow embedded in a VF page)? Thanks!
tengeltengel
@Ashley Sisti, if you are using Visual Workflow for your solution, Loops and Collections will be generally available in the Summer '14 release of Salesforce! These features will make a much easier job of looping through collections of records, updating them, etc. See page 191-192 in the Summer '14 release notes (https://help.salesforce.com/help/pdfs/en/salesforce_summer14_release_notes.pdf). If you can hold off until then, I would highly recommend it! Although my solution works right now, I will definitely be rebuilding the flow to take advantage of Loops and Collections.