Enabling Account and Opportunity Teams on Salesforce1 Declaratively

Jay Desai
Salesforce Sage

--

One common use case for Salesforce1 is the ability to manage your Account and Opportunity Team members. There is some support for this, however, it is limited, missing some key features. Opportunity Team Member support includes the viewing and editing of Opportunity Team Members, but not the ability to add. For Account Team Members, you can view them, but you can’t add or edit them.

The can easily remedy this through a combination of VisualForce and Actions, however, there is also a declarative way to meet the same goal using Process Builder for the Add functionality. This tutorial walks you through how to enable the ability to add Opportunity Team Members utilizing Tasks and Process Builder. The same pattern would apply to adding Account Opportunity Team Members.

A. Modify the Task Object

Since the Task object is supported as an Action, we can leverage it to create an Opportunity Team Member Task. This will be a temporary task which will be used to collect the information needed and then used to create the Opportunity Team Member entry through Process Builder and Flows. The task will be deleted at the end of the process.

Step 1: Add fields to the Task Object to mirror the fields in Opportunity Team Member in Activity Custom Fields as shown in Figure 1. For the Picklist values, add entries that exactly mirror their Opportunity Team Member field counterparts. They do not need to be in any page layout.

Figure 1

If you have Record Types for Tasks, make sure the Picklist fields are added for the Record Type you will use to create the Task Action.

Step 2: Add an entry to the Task Type field so we can define a task as type “Opportunity Team Add” in a future step. The entry can be any descriptive value you would like, but in this tutorial we will use “Opportunity Team Member”.

B. Create The Action

On the Opportunity object, create an object-specific Task Action:

Step 1: Create the new Action as shown in Figure 2. If you have Record Types for Tasks, you’ll see an additional field asking you to select a Record Type. Make sure you select a value other than “Master” otherwise the action will no display in Salesforce1.

Figure 2

Step 2: Modify The Layout as shown in Figure 3. When you save, do not worry about the error message on required fields, we will handle that in the next step.

Figure 3

Step 3: Handle the required fields by creating predefined values for them as shown in Figure 4. We will also add a predefined value for the Task Type field to flag this Task as a Task that is created to add an Opportunity Team Member.

Figure 4

Step 4: Add the Action in the appropriate Opportunity page layout in the “Salesforce1 and Lightning Experience Actions” section.

C. Create the flow that will convert the Task to a new Opportunity Team Member record

Step 1: Create a New Flow

Step 2: Create the Flow Variable

Create a sObject Variable to hold the Task record passed by Process Builder as shown in Figure 5.

Figure 5

Step 3: Create the Opportunity Team Member record by using the Record Create element as shown in Figure 6. You’ll notice we can’t assign a value to the OpportunityAccessLevel field. By default, this field will be set to the least privileged setting (read). If this is all you need, then you’re all set. However, if you need the ability to select between read-only and write, I have a work-around at the end of the steps.

Figure 6

Step 4: Clean-Up

Delete the Task record using the Delete element as shown in Figure 7. If you have feed tracking enabled for Tasks, add an extra step to delete the corresponding Feed Item.

Figure 7

Step 5: Activate the flow. In order for the flow to show up in Process Builder (next step), it’ll need to be active.

D. Create the Process Builder Flow (Last Step!)

Let’s jump right in by kicking off a new Process Builder flow and then:

Step 1: Select the object the Process Builder should trigger off of. In this Case Task and select the “only when record is created” radio button.

Step 2: Add Criteria as shown in Figure 8. The conditional logic specifies that this flow execute only if the Task is of type “Opportunity Team Member”. This is the default value we have set on the Action for the Type field we created earlier.

Figure 8

Step 3: Create the Immediate Action to launch the flow as shown in Figure 9. In this step you create an action that will launch the flow you created earlier. You will pass the Task record that triggered Process Builder to that flow.

Step 4: Activate the Process Builder Flow

Final Step

Try it out! Open Salesforce1 and navigate to the Opportunity Record. There you should see the Action (make sure you’re on the right Page Layout). Fill int the fields. Once done, navigate to the Opportunity Team related list where you’ll find the person you just added (may need to refresh by pulling down).

Work-around for modifying the OpportunityAccessLevel field

You can modify the OpportunityAccessLevel once the OpportunityTeamMember record is created through the OpportunityShare object. This is similar to what you would do for the Account Opportunity Team Member Access Level’s utilizing the AccountShare object. This has several implications:

  • The OpportunityTeamMember record needs to be created and committed to the database first. Commits happen when the Flow is completed. So we would need to break this flow into two flows. One that creates (Create Flow) the OpportunityTeamMember entry and then one that updates it (Update Flow). Both flows can be called from Process Builder.
  • We can add conditional logic using the Decision element in the Create flow to only delete the task if the OpportunityAccessLevel is “read” since we do not need to go to the Update Flow in that scenario as that is the default value. If it is “edit” the delete can occur in the Update Flow.
  • We can add conditional logic in Process Builder only to execute the Update Flow if the OpportunityAccessLevel is “edit” so we are not doing any unnecessary DML operations.

To create the Update flow, you will need to create a simple VisualForce class that can be accessed through the flow by creating a class the implements Process.Plugin (not hard). An example of the code:

Once you create the class, it’ll be available in the Visual Flow Palette tab under the description we gave it in the class (“Opportunity Classes”).

Quick Steps to create the Update Flow:

  1. Create the sTask sObject Variable
  2. Add the class element to the design pane in fill in the appropriate fields. It should look similar to figure

3. Add the Delete Element

4. Add Conditional step to Process Builder to launch this flow only if the you want to change the Access Level to “edit”.

PARTING NOTES

As with everything, build this in the sandbox and test it out! There could be triggers or other things that could conflict with this that may need to be taken into consideration (even if you did all of this in Visualforce code). As always, governor limits apply.

Special thanks to my colleagues at Salesforce who’s work helped contribute to this article — KK Ramamoorthy (using Tasks with Process Builder to create actions for non-supported objects) and Jeff Douglas (code for modifying Access Levels).

--

--