Imagine Michelle Gregory (Salesforce Administrator) working at The Stark Industries got a requirement from her VP asking her to clone the Opportunity Contact Roles of a closed Opportunity as Account Contact Roles i.e., whenever an Opportunity gets closed, all it’s Opportunity Contact Roles should be cloned as Account Contact Roles. She started to research and began her quest in search of a solution. She researched quite a lot but all her efforts went in vain. Every search result took her to a solution that involved Apex. Unfortunately, Michelle being a hardcore Admin didn’t know to write a single line of Apex. But she knew how mighty Salesforce is and its power to get stuff done with point and click.
That is when she accidentally came across a feature called Flows. And then she thought, why not try her luck with the Flows?
Here is the Entity Relationship Diagram to get a better picture about the objects involved –
There are primarily two ways by which we can clone Opportunity Contact Roles of a closed Opportunity as Account Contact Roles:
We can create an Apex Trigger which would be fired on every Opportunity update and looks at the Stage Name of the Opportunity. If it is ‘Closed Won’, then query all its Opportunity Contact Role records and clone them as Account Contact Role records.
But we can’t expect a Salesforce Admin to write an Apex Trigger.
We can create a Visual Workflow and invoke it via a Process. Whenever the Stage Name of an Opportunity record is changed to ‘Closed Won’, the Process will invoke a Flow which would clone all its Opportunity Contact Role records as Account Contact Role records.
Here are some screenshots of how you should go about setting up the Process –
Once the Process has been set up, the next thing is to set up the Flow. And trust me, setting up the Flow is very easy.
Here is a screen recording detailing how I have set up the Flow –