Business Problem

The sales team would like to report on the last meeting date for a Contact but when we try to use the standard Last Activity field, we see there are dates in the future. In order to solve this, we need to create a new custom field and update it with the meeting date after the meeting occurs. We only want the new field on the Contact to be updated if the date/time of the event record is in the past. In order to achieve this, we need to create a couple of things in Salesforce.

  • Last Meeting Date – date/time field on the Contact object
  • Schedule-Triggered Flow – this is a new exciting feature Salesforce has added to flow. It basically replaces the need for us to custom code a batch process. We are using a schedule-triggered flow because if the user does not edit the event record after the meeting has passed, then it will not trigger a record-triggered flow or a process builder. Schedule-triggered flow allows us to schedule a specific time to run a process on a set of records. Check here for more information on Schedule-Triggered flows from Salesforce.

Please note there are several considerations to using this feature:

  • There is a 250,000 limit on schedule-triggered flows, or the number of user licenses in your org multiplied by 200, whichever is greater. One interview is created for each record retrieved by the schedule-triggered flow’s query.
  • If you configure an Update Records element to use the ID and all field values from the $Record global variable, enable Filter inaccessible fields from flow requests in your org’s process automation settings. Otherwise, the flow fails because the Update Records element tries to set the values for system fields and other read-only fields.
  • View your scheduled flows under Scheduled Jobs.
  • The scheduled flow will run in the same time zone of your org – this is set under Company Information.

How to Build the Flow

Here is what the final flow will look like:

  1. Go to Flows | New Flow and select Schedule-Triggered Flow

2. Configure the Schedule. Remember to schedule the time based on your org’s time zone, not your user’s time zone.

3. Configure Choose Object and Filter Conditions. We are filtering for Event records where there is at least one attendee.

4. Drag and drop a Decision Element onto the canvas and configure. This is needed because we could not specify this criteria in the filter conditions in the previous step.

5. Drag and drop a Get Record element onto the canvas and configure. We are looking for all of the attendees on the Event record, so we are querying the Event Relation object.

Please note: In order to see the Event Relation object, you must have the setting enabled under Activity Settings: Allow Users to Relate Multiple Contacts to Tasks and Events

5. Drag and drop the Loop element onto the canvas and configure it to loop through the Get Attendees record collection.

6. Drag and drop the Decision element onto the canvas and configure it to filter for only Contact records. If you have Leads and Contacts on the same event record, this is will help you split the process so you can update Leads and Contacts separately. We are only solving for Contacts in this example.

{!Loop_Attendees.RelationId} Starts With 003

7. Create a Record Variable to hold the values for the Contact records.

Then drag and drop the Assignment element onto the canvas and configure it to assign the Contact ID and Last Meeting Date fields in the record variable.

    {!varContactfromAttendee.Id} Equals {!Loop_Attendees.RelationId}

    {!varContactfromAttendee.Last_Meeting_Date__c} Equals {!Loop_Attendees.Event.StartDateTime}

8. Create a Record Collection Variable for the Contact object to hold the records that need to be updated.

Drag and drop the Assignment element onto the canvas and configure it to add the Contact records to the Record Collection.

   

9. Drag and drop the Update Records element onto the canvas and configure it to update the Contact Record Collection.

   

Save your changes and click Debug to make sure the flow is working properly. Click Activate when you have completed testing.

   

Please note this flow will not update all of the Contacts with their most recent event date/time, it will only update Contacts with an Event where the date/time occurred yesterday. If you would like to update historical records, first check the number of event records you have in your org. If it is under the limits for Schedule-Flow triggers specified above, you can modify this flow to run for ALL event records, just change the arrow from the Start element to go directly to the Get Attendees element (skip the Decision Element called Event Occurred Yesterday) and make sure the Get Attendees element is configured to sort Event Relation Records by date. Unfortunately, there is not a way to sort the records by Event StartDateTime, you can only use the date/time fields on the Event Relation record – SystemModstamp, CreatedDate or LastModifiedDate are the only choices. Knowing this, you may want to update the historical Contact records manually using some Excel and Data loader work.