Your company has a business model where multiple sales people representing different channels or product focuses, or an internal/external sales team, may interact with the same individual. There is a business need to track calls to the contact or events with the contact and to easily know when the last time a contact was called or met with.
These two use cases will be covered in a 2-part article series.
- Record the last call made to a contact
- Record the last event with the contact
This article will cover the use case to track the last call made to the contact in Salesforce. While this can be done in custom code, we are able to accomplish this with visual workflow and a small snippet of visualforce to invoke the visual workflow. Note: This works in both Salesforce Classic and Lightning Experience.
Here are a few lessons learned from implementing this use case:
- Provide descriptions, where provided, in Salesforce. This may be tedious step, I know, but your future self will thank you when you are trying to remember what you configured or assist other/future admins when troubleshooting or enhancing what was built. This includes noting the data stored in a custom field, noting where a visual flow is invoked from, the purpose of a flow variable, what a visualforce page does, etc.
- You can initiate a visual workflow from a detail record page by embedding a visualforce page that invokes the visual workflow in an object’s page layout. To see the results of the visual workflow, you need to refresh the detail record. Since this only updates when you refresh the page, if the business need is to be able to report on this data, then you will have to go the code route. If all you want to do is see the last time you called a contact on the record, then this will suffice.
- If a previously created call task is deleted from the contact record, upon the next visit to the detail contact record will recalculate and remove the deleted call task from being evaluated for display on the Last Call Date field.
- For any data actions (fast and record lookup, create, update and delete actions) performed in visual workflow, best practice is to include a flow element to send an email to your Salesforce administrator about the fault.
Flow trick: To getting the Fault connector to appear, either draw the regular connector link to another flow element or connect it to a temporary flow element. Draw the fault connector to the Send Email element. Then, go back and delete the regular connector.
Business Use Case: Addison Dogster is a system administrator at Universal Container. Sammy Sunshine is a Sales Manager who requested that we track the most recent call made to a contact in Salesforce when he is on the contact detail screen.
Solution: Addison was able to help Sammy through declarative actions with two custom fields (Activity and Contact objects), a visual workflow, a visualforce page that invokes the visual workflow and an update to the contact page layout(s) to add the Last Call Date field and the visualforce page.
Quick Steps:
- Create an Activity custom field (Customize | Activity | Activity Custom Fields), create a new field that will calculate the difference between today’s date and the call date (i.e. task due date, or API Name: ActivityDate). We will use this to determine the most recent call task date.
1a. Set the field level security accordingly – make it visible to system admins and most likely, not other users.
1b. This formula field is used for processing so you do not need to add it to a task or event page layout.
2. Create an Contact custom field (Customize | Contacts | Fields), create a new field that will track the most recent call task date.
2a. Set the field level security to be visible for all applicable profiles and editable to profiles that would create call tasks.
2b. Add this field to the contact page layout where you’d want to track the last call date. Mark this field on the page layout as Read Only.
Best practice tips for custom fields:
- Don’t forget to provide a description so you and other/future admins know what these fields are used for.
- Set the FLS (field level security) for each profile. Only make the field visible and editable for the profiles that need it. Do not just click the “Next” button when you are on the screen.
- Select only the page layouts that the new fields need to be added to. By default, new fields are added to all page layouts. Once the field(s) is/are added, you may need to update the page layout to move the field(s) to the desired location on the page.
3. Create a visual workflow (Create | Workflows & Approvals | Flows). This flow will perform a lookup of call tasks for the specified Contact based on the smallest positive duration from the call task’s date and today’s date and update the Last Task Date field with the most recent call task date.
A. We need to create two variables that will be used in the visual workflow per the screenshots below. One will contain the Contact ID (varContactID) and the other will contain the call task’s date (varActivityDate).
Best Practice Tip: Don’t forget to provide a description so you and other/future admins know what these fields are used for.
B. Next, we will create a Record Lookup flow element. This will lookup the contact’s call tasks that have a positive duration (difference between the activity date and today’s date). Take the smallest duration difference and take the ActivityDate value for that call task and update the ActivityDate variable.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this record lookup will do.
C. Make sure this flow element is “Set as Start Element.”
D. Create a Record Update flow element to update Last Call Date field with the value in varActivityDate variable in the Contact record where the ID matches the varContactID variable that will be passed from the visualforce page.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this record update flow will do.
E. As a best practice, where there is a DML action (fast or record create, update, delete or lookup action) in a flow, you should also include notification of a flow fault.
Note: To avoid “hardcoding” email addresses in a fault email, refer to a post Using Custom Metadata Type in Visual Workflow Fault Emails.
Select the Send Email flow element that is listed under Static Actions, not under Quick Actions.
Configure the body to show the fault message, subject and email address(es).
Body: Fault Message: {!$Flow.FaultMessage}
Subject: Error – Update Contacts Last Call Date
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this send email element is supposed to do.
You will need to draw a connector line between the Record Update and Send Email elements.
Can’t seem to get the fault connector to appear? Create a temporary flow element (circled below), draw your first connector to that temporary flow element. Then, draw another connector to the send element. This connector has the word “FAULT” in it.
Once that is completed, delete the temporary flow element you created. This is the end result.
F. Provide a name for your flow and ensure that the type is flow, not autolaunched flow.
Note: You may need to do a save as twice as a flow as it appears Salesforce, by default, does the first save as an autolaunch flow instead of a flow. Just delete the autolaunch flow later.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this visual flow is used for, where it is invoked from.
G. Click the “Close” button.
H. On the flows screen, activate the flow.
4. Create a visualforce page (Develop | Visualforce pages) that invokes the visual workflow.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this visualforce page is supposed to do.
Don’t let this part scare you. I’m not a developer so if I can copy, paste and tweak, so can you. I quote Mike Gerholdt at the Dreamforce 15 Admin Keynote “There is no shame in copy and paste.”
Here are the contents of your visualforce page:
<apex:page standardController=”Contact“>
<flow:interview name=”Update_Contacts_Last_Call_Date“>
<apex:param name=”varContactID” value=”{!Contact.Id}”/>
</flow:interview>
</apex:page>
Let me explain the bolded items you will need to modify in your visualforce page:
- standardController: Reference the object (API name) that this visual flow will execute on.
- interview name: This is the name of your Flow Name.
- param name: This is the variable name in your flow. In this example, we are passing the contact record ID as variable varContactID used in the visual flow. Note: The variable name must match exactly to the variable name in your visual flow.
5. Update the contact page layout to add the visualforce page. Set the visualforce page properties to 0 width and 0 height since the visualforce page does not need to show on the actual page layout.
6. Add the newly created visualforce page to the profile(s) that need to execute the visual workflow. By default, it is automatically added to the System Administrator profile.
7. If the “Run Flows” permission is not enabled for the profile who will need to update the Last Call Date, you need to enable this under System Permissions.
That’s it. Congrats, you’ve implemented the solution!
Now, before you deploy the changes to Production, you need to test your configuration changes.
- Login as a salesperson and navigate to a contact record.
- Log a call.
- Refresh the contact record.
- Verify that the Last Call Date is updated to match the task due date from Step 2.
- Repeat this for each profile that has access to this field.
Deployment Notes/Tips:
- The activity and contact custom fields, contact page layout(s)* and visual workflow can be deployed to Production in a change set.
*Assuming your page layouts are in sync with production (only includes the new custom field and not others in progress), you can deploy page layouts in a change set. Otherwise, if you are not sure, I suggest manually adding the new field to the contact page layout in Production to avoid accidentally overriding production with an older version.
- The field level security for the custom fields and the “Run Flows” system permission enablement will need to be manually updated post deployment. I would caution against adding the related profiles in the changeset for deployment as the results of deploying a profile are not reliable. If you have a tool like Snapshot by Dreamfactory, you can use the tool to deploy field permissions and profile system permissions.
- Activate the visual workflow after it deployed in Production as visual workflows are deployed as inactive.
Hi, i have followed all your steps and when i paste in the Visualforce Page with the text you have shown, i get the following error , “Error: is required and must be the outermost tag in the markup at line 1 column 1”
Any advise?
LikeLike
Do you have access to the success community where you can post screenshot to show me? Are you working in a Spring 16 or Summer 16? The VF page to invoke the flow and pass the variable is pretty bare bones so not sure why it would be causing an issue.
LikeLike
Hi jenwlee. This is a great solution. Is there anyway to build an automated contact page refresh into the flow/process, my users are not going to like having to do this manually.
LikeLike
You want to refresh the page after update, you will need to engage a developer to write code to do this.
LikeLike