Get last task or event date against multiple contacts in Salesforce (on create/update)
Quite often a question bothers business users as well as functional experts how to get latest event/task date for a particular contact in Salesforce and plan a communication based on contact activity report, like ones with last activity past one month etc.
Last modified date or only Last activity date on Salesforce record is not a true indication of latest communication done with that contact/lead/account. Its actually the latest event or task associated with respective lead, contact or account.
The document below explains setup and technical implementation of the same.
This might sound easy, but it’s not easy as just go
and put LastModifiedDate of that Contact on Report. It’s bit challenging.
Getting right Last Task Created Date for
Task which is associated with 2 or more Contacts becomes challenging, as by default it takes first contact associated to that Task and puts task created date
on that first contact only. :)
After spending much time on Apex Triggers, we thought that Instead of Record Triggered Flow let’s make a combination of Process Builder and Flows.
Here are some objects which we use in this solution:
1. 1. Task Object:
In task object, we have task id (ID),
contact associated with that task (WhoId), account associated with task
(WhatId), How many contacts are associated with the task (WhoCount).
2. TaskWhoRelation Object:
In this object, we have Task Who
Relation Id (ID), associated person to Task (RelationId), associated Task
(TaskId). In this example, it shows 6 people records associated to the same
task.
1. Create
two custom fields Last Task Created Date & Last Event Created
Date on Contact Object.
2. Make
a Process Builder on Task with entry criteria when task is created or updated. And
Criteria condition is Task.WhoId IsNull False, after that put Flow as Immediate
Action.
3. Make Autolaunched
Flow.
Quick Steps (Flow):
a. Get
Contacts associated to Task: Get records of TaskWhoRelation object. Filter this object by condition TaskId
Equals text Variable. And store Id and RelationId
in one collection Variable.
b. Records Found: Decision for checking whether that collection variable is not null. Records Founds outcome looks at the items in the {!collectionOfContact}
c. Loop: Now
we need to create a LOOP flow element so that we can go through each TaskWhoRelation
record in collection. It looks at the Record Collection Variable {!collectionOfContact}.
f. Update
Contact: For each loop record, in the Assignment flow element, we will assign
the Last Task Date to taskDate variable.
g. Add
to Collection: For each loop record, in the Assignment flow element, we will
add the loop record to a new collection that will be updated.
h. Update
Task Date: Next, we need to create the Update Records flow element to update
all the contacts in collection variable.
Flow Debug:
Pass appropriate task record and debug the flow successfully.
The latest activity (when Task and Event is created or updated) on Contacts Report can be displayed too.
Do share your views.
By: Kimaya Shirude ;
Salesforce developer - Thutech Infosystem
www.thutechs.com
This is really helpful for right contacts communication. Liked the way its explained.
ReplyDelete