Counting contacts is not so easy
Counting contacts is not so easy when you start digging into it. When you need to count the number of contacts on an Account record, it initially seems pretty simple. Just create a record triggered flow to run each time a new contact is created, have the flow loop thru and count how many contact records there are for the account referenced in the contact and update a count_of_contacts custom field on the account.
What about Deleted Records?
What a lot of people forget is what if a record is deleted? You have to calculate the number of contact records that are left (or just reduce the existing number by one).
For Flow, you only have the following choices for a trigger:
You need to create a second flow to handle the delete records.
But, the complexity does not stop there!
There is one more gotcha!
The purchasing Manager at ACME, let’s call him Bob – is a long term customer and has purchased lots of products over the years. There are many recorded emails, tasks, calls and appointments that are visible in the activity panel when viewing Bob’s contact record. The owner of Bob’s record has been diligently following best practice and ensuring everything is properly documented.
Bob decides to leave ACME and gets a new job as Global Purchasing Manager at RoadRunner Inc. This account is owned by another Sales Rep. When trying to add the new contact record for his new customer, the Sales Rep finds there is a duplicate record warning message. He then decides the easiest way to add this new contact record is to simply make the updates to the existing record and proceeds to update the new Job Title, Email and phone numbers on Bob’s contact record and re-parent the record from ACME to the RoadRunner Inc Account. Sounds good so far??
If you know the Road Runner cartoon you know that Wylie Coyote and the Road Runner are fierce rivals! Wylie Coyote purchases all the devices to attempt to catch the Road Runner from ACME.
Now when the Sales Rep for RoadRunner Inc (the new owner of Bob’s contact record) views Bob’s contact record it still contains all the previous activities that occurred when Bob worked for ACME. Imagine what could happen if the new Sales Rep clicks on one of those old emails and forwards it to Bob at this new company. Even worse if it has a long threaded conversation.
Let’s introduce AI into the mix and start making predictions and recommendations that may include these old emails, meetings, tasks etc. We could not only have a very messy situation, we could also have a privacy nightmare that I’m sure will be a breach of GDPR.
So how do we prevent this?
First we need to treat Bob at RoadRunner Inc as a new person – create a completely new contact. The only thing he has in common with the old Bob at ACME is the name. His phone number, email, address and job title will all have changed.
A simple validation rule on the contact record will stop his old record being reused and re-parented to the new Account.
Refer the user to their System Administrator to perform corrections for them if they made a mistake when creating a contact record.
I hope you are now more enlightened and understand that counting contacts is not so easy!