Blog

In this post, we are going to explore how Visual Workflow can be used to clone opportunities and line items. Yes, Salesforce does has a ‘Clone with Products’ and ‘Clone without Products’ option on a single record, but what if your requirements are more complex than that? For example, you may want to control which fields are cloned, or use a naming convention on the cloned opportunity, or set particular field values. You may also want to search for a set of past opportunities, and be able to clone multiple opportunities at once.

This example will show how to clone multiple opportunity records, including the opportunity products, on a list view by calling a Visual flow from a custom button.

Step 1: Calling the Flow from a custom button on a list view
  • The flow is initiated by creating a custom button on the opportunity object
  • The button is associated with a VisualForce page that has a StandardSetController
  • The button needs to be added to the list view layout.
  • Take note of the name on the <apex:param tag which will be used as an SObject Collection on the flow itself.
  • The name on <flow:interview VF page tag points to the name of the flow and initializes it as well.
visual-workflow-1
clone-flow
flow
Step 2: Loop through the selected Opportunity Records
  • The green arrow indicates the flow starting point.
  • The loop iterates through values of the OpportunityCollection (an sObject Collection) of selected records:

    [crayon-6114a4c163c07988492934/]

  • This is how the records chosen from the list view passed to the flow.
  • The loop will continue until all records are processed.
loop
loop1
loop2
Step 3: Record Lookup
  • The OpportunityClone loop processes records one by one.
  • At this stage, each record from the OpportunityCollection will be passed to the OpportunityCollectionVariable and will be queried based on the criteria.
  • Variables that will store the fields to be added in the clone are defined.
record-lookup2
Step 4: Create the Opportunity Record
  • The next step is to create an opportunity record and assign field values
  • Field values can be assigned through the previously queried flow variables
  • It is important to save the new opportunity Id to a variable, as it will to clone the opportunity line items/products.
records-create
records-create-2
Step 5: Create the Opportunity Line Item records
  • As compared with Record Lookup, Fast Lookup can deal with multiple sObjects or collection of sObjects.
  • This is suggested to be able to deal with two or more opportunity line items per opportunity.
  • This block will query all the opportunity line items based on the source OpportunityId
fast-lookup
fast-lookup2
loop3
loop4
  • This loop will iterate all the records queried in the previous Fast lookup (stored on the OpportunityLineItemRecords collection variable).
  • As with the first loop, this will iterate until all records are processed.
  • The records will be saved one by one in the OpportunityLineItemRecordsVariable variable during processing.
record-create-3
record-create-4
  • As with the CloneOpportunity Record Create, this is where the cloning of opportunity line items/product takes place.
  • New records are created with the same field values as the original records.
  • As you can see, arrows are pointing to each other, meaning, as long as the loop still have line items records to iterate, it will continue to create, otherwise, it will go back to the first opportunity loop for the next opportunity record, if there are any.
screen

The Flow in Action

  • The following screenshots show 3 records selected, using the Clone button and the resulting cloned record, including the opportunity products.
sample-rec
successfully-cloned
sample-rec-1
sample-rec-2

What Certification are you studying for now?

Focus on Force currently provides practice exams and study guides for sixteen certifications

Clone of Opportunities and Line Items using Visual Workflow

In this post, we are going to explore how Visual Workflow can be used to clone opportunities and line items. Yes, Salesforce does has a ‘Clone with Products’ and ‘Clone without Products’ option on a single record, but what if your requirements are more complex than that? For example, you may want to control which fields are cloned, or use a naming convention on the cloned opportunity, or set particular… Read More

Clone of Opportunities and Line Items using Visual Workflow

5 Free Salesforce Career Game Changers

By Amanda Bailey Every day people read job descriptions for their dream positions and feel frustrated when they get to the “required skills” section because it has 20 skills that they don’t have. In most industries, it would require extensive classes, possibly college courses and more to be able to gain those skills. Fortunately, with Salesforce they want you to grow and the community of people who work with the… Read More

5 Free Salesforce Career Game Changers

Focus on People: Peter Yurchision

Curiosity, Google, and Salesforce Help Today I’m writing a post explaining my path to becoming involved in the world of Salesforce. As a current freelance Salesforce Admin/Business Analyst/Consultant, my career plans did not include managing a Salesforce Implementation. Yet, six years after first logging into Salesforce as an inside sales rep, I can’t image a better way to spend my working days. I hope my story inspires you to become… Read More

Focus on People: Peter Yurchision

Customer Service Project Case Study

In this post Jasmin Ashley, a senior functional Salesforce consultant, shares a case study of using Salesforce to improve customer service by implementing a case management solution, including email to case, queues and omni channel routing. The project goal was to create a case management solution using email to case and Omni channel routing. All cases feeding through from one email address and routed to the appropriate business team to… Read More

Customer Service Project Case Study

Salesforce Data Security

By: Nick Kurbatov, Digital Business Analyst Data Security – when I see these two words – the first thing that comes to my mind is “Johnny Mnemonic”, where the brain of the main character is used as data storage and antagonists are trying to break and steal the data. Data Security is without a doubt one of the biggest trends in IT nowadays. According to the current speed of the… Read More

Salesforce Data Security

Salesforce Pending Approvals Report

If you have one or more approval processes, you may find a requirement to be able to report on records that are pending approval. As well as knowing the records, we probably will want to know who the record has been assigned to for approval, so we can follow up or reassign if the person is not available. If you have a look at the standard reports, you won’t find… Read More

Salesforce Pending Approvals Report

Focus on People: Julian Virguez

Getting involved in Salesforce can accerlerate and move your career in different directions. Julian started working with Salesforce technology a number of years ago as a developer and has progressed to becoming a Salesforce technical lead / scrum master. Here Julian tells us more about his journey so far. How and Why did you get started with Salesforce? I started working with Salesforce by chance, while I was working for… Read More

Focus on People: Julian Virguez

Sorting Lists in Salesforce

By Amelia Brewin Sorting objects is a requirement that comes up from time to time. It can be as simple as ordering by a simple number field (such as Opportunities priority) or more complex ordering involving multiple fields. Luckily for us Salesforce has the Comparable Interface. With a handy wrapper class that implements Comparable and takes our object in the constructor we can define our own ordering. This list is… Read More

Sorting Lists in Salesforce

Deploying with ANT

As Salesforce projects and deployments get more complex, it is a good idea to learn more about the different deployment options that Salesforce provides. When starting with Salesforce, you learn about how change sets can be used to deploy changes between related orgs. Change sets are only one of the many ways available by which you can deploy one Salesforce Org’s components to other. For example: Change sets Eclipse IDE… Read More

Deploying with ANT

A Data Quality Project

By: Nick Kurbatov, Digital Business Analyst Data Quality – what do you think about when somebody mentions these words? Have you ever imagined what would happen if your address book or files on your computer suddenly go mad, because there are no unique identifiers(IDs) in your data? It would be a mess. You wouldn’t be able to easily find your colleague’s date of birth or the name of your favorite… Read More

A Data Quality Project

Succeeding with Salesforce1

By: Nick Kurbatov, Digital Business Analyst “Welcome to the digitized world”– that could be Morpheus’ phrase in the movie “The Matrix” if Neo was awoken in 2016. Data storage devices as well as computers and smartphone have advanced significantly over the last 20 years. Moore’s law has already died by now. Every year manufacturers of smartphones create faster, smaller, and more intelligent mobile devices. The same thing happens with software…. Read More

Succeeding with Salesforce1

REST API using Weather Example

Sometimes you have a requirement to access information from an external source and store or display in Salesforce. One way of doing this is by making a REST API call from Salesforce to an external endpoint. In this example, we show step by step how a call using the REST API can be made to an external site to retrieve weather information related to an Account. We will be using… Read More

REST API using Weather Example

Work Orders in Salesforce (Spring’16 Release)

If you have had a requirement to track field service in Salesforce, up until recently, you had two options: create a custom solution, or implement an AppExchange solution such as ServiceMax. Now, with the recent Spring’16 release, Salesforce have added the beginnings of a field service solution. The initial functionality is centered around Work Orders. Work Orders is the central object used to track repairs, perform maintenance activities and other… Read More

Work Orders in Salesforce (Spring’16 Release)

Osler: From Idea to AppExchange

Interview with Steve Sacks, Founder/Director at Osler Technology Most of us using Salesforce use one or more AppExchange Apps to supplement and expand the functionality available to us. Apps range from small point solutions, such as address validation to the larger apps that address a need such as document generation (e.g. Conga) to Apps that sit on top of Salesforce that are focussed on the needs of a particular industry,… Read More

Osler: From Idea to AppExchange