Posted by Julianne Boley
Have you ever wanted to automatically update every record in a related list, or post something in a Chatter feed, or create a record without writing an Apex Trigger and test class? It’s possible with the Process Builder!
The users would like a Contract to be automatically created every time an Opportunity reaches a stage of “Closed Won.” They would like the Contract record to reflect a status of “Activated” and a start date that is equal to the Opportunity’s close date.
We’ll use the Process Builder to accomplish everything required, eliminating the need for custom coding.
Step 1: Open the Process Builder & Create a New Process
You’ll find it by searching within the setup menu or by navigating to Create>Workflow & Aprovals>Process Builder:
Click on the “New” button and walk through the screens to give your new process a relevant name:
Step 2: Choose the Object that will Kick Off the Process
Click on “Add Object” and select the object which contains the records that will kick-off the process. In our example we will choose the Opportunity object because we want to base our criteria on a field (Stage) that exists on opportunity records.
Step 3: Specify the Criteria that Needs To Be Met to Kick Off the Process
Choose when you want the records evaluated by the process by selecting whether they need to meet certain criteria, or whether a formula you specify is true, or just choose to evaluate all records.
In our example, we want the record to meet specific conditions (Stage = ‘Closed Won’)
We also have the option of using AND, OR, or Custom logic between our conditions and under the Advanced menu, we can choose to only evaluate records that meet our specified conditions now, but didn’t prior to being edited. Since I don’t want to create a contract every time an Opportunity that has a Stage = ‘Closed Won’ is edited, I’ve chosen to check that box. This means that the actions will only be executed when the Opportunity Stage field is edited to ‘Closed Won’ and didn’t meet that criteria in a prior edit.
Step 4: Select and Define Actions
The Process Builder is like a workflow rule on steroids. Instead of being limited to field updates, email alerts, and tasks, you can do any of those plus many more advanced things like executing Apex, kicking off a flow, auto-submitting records to an Approval Process, etc.
For our example we are going to choose to “Create a Record” and we’ll choose the “Contract” object as the type of record that we want to create.
Now we can specify the values that we want to be in the fields on the new Contract record that we are creating:
When you select a field, you can traverse object relationships to get to fields on other related records (those indicated with the >) that you may need:
Step 5: Activate!
Now that we have specified created our Contract and told the process what values we want in the Contract fields, we only need to Activate the process to begin auto-creating records.
No trigger or test class needed!
To learn more about the Process Builder and work through your own practice exercise visit the Process Builder Trailhead Module or contact your Buan Consultant.