back to blog
Making one Contact as a Primary Contact
January 24 2024 • 20 min read

BUSINESS CHALLENGE

In an Account object, the Contacts appear in the related list – which is in a separate tab. It will be a better user experience if the Primary contact appears on the Account Details page.

REQUIREMENT

We are mentioning here the two possible requirements to achieve this. 

  1. Manually assign the primary contact in the Account object Detail section. In this scenario, the Contact object does not have any knowledge of Primary Contact.
  2. When creating a contact, set that Contact as Primary contact using a new checkbox field “Primary Contact” – which should then populate this contact on the Account object to display in the Detail section.
    1. Create a Checkbox field with the name “Primary Contact” on the Contact object. Create a Text field in the Account object to display the primary contact.
    2. If there are no other primary contacts, set this contact as Primary contact and show it in the Details page of the Account.
    3. If there are any other contacts already set as Primary contact, this contact should override the previous Primary Contact and notification should be sent to the old and new primary Contact owners that there is already a Primary contact and is overridden.

STEPS TO ACHIEVE THE FIRST REQUIREMENT

Through the Lookup field we can make the Name of the Primary contact to be set/displayed on the Account Object.

  1. Create a Lookup field on account:

    1. Go to setup click object manager and select account
    2. Click on Fields & Relationships click New.
    3. Select Datatype as a Lookup Relationship 

  1. Click Next
  2. Choose Contact as Related Object

  1. Click Next
  2. Enter “Primary Contact” as Field Label.

  1. Click Next, Next, Next and then Save.

This new field will be added to the Page Layout in the details section. 

Users can select the primary contact in the account details page as shown in the screenshot below.

STEPS TO ACHIEVE THE SECOND REQUIREMENT

  1.  “Primary Contact” Checkbox field in the Contact object
  2.  Create Custom Notification Type
  3.  Create a record triggered flow to update the Primary Contact field for non      primary contacts and the Primary Contact in Account object.
  4. Add “Primary Contact” Checkbox field in the Contact object
    1. Go to Setup, then click Object Manager | Contact.
    2. In the sidebar, Click Field & Relationships.
    3. Click New.
    4. Select Checkbox as the Data Type.

  1. Click Next.

  1. Click Next.

  1. Click Next & Save.
  2. Create Custom Notification Type
    1. Goto Setup, In quick find box type Custom Notifications, then select Custom Notifications.
    2. Click New

  1. Enter Custom Notification Name, API Name is automatically populated.
  2. Supported Channels select only Desktop.

  1. Click Save.
  2. Create a record triggered flow                                                                                                                                                    

  3. To create Record Triggered Flow, Go to Set up –> Search Flow Click on New Flow.

  1. Select Record Triggered flow  → Click Create.

By default the layout is set to Auto Layout.

  1. Select Object as Contact

Choose “A record is Created or Updated” option for “Configure Trigger”.

Optimize the flow for →  Select Actions and Related Records.

  1. Next step is to Get the Previous Primary Contact using Get Records Element
    1. Select (+) icon → Select Get Records Element.
    2. Choose Contact Object
    3. Select All Conditions are Met(AND) as a condition requirement
    4. Set the following conditions as mentioned in the screenshot below.

Account Id →  Equals → Record Account Id → Account Id

Primary Contact →  Equals → True

Id →  Does not equal →  Record Contact Id

  1. Under How many records to store select Only the first record.
  2. Under How to store Record Data  select Automatically store all fields

  1. Create another  Get Records Element to get the Notification Id of the previously created Custom Notification Type to send notification.
    1. Select (+) icon → Select Get Records Element.
    2. Choose Custom Notification Type Object
    3. Select All Conditions are Met(AND) as a condition requirement
    4. Set the following conditions as mentioned in the screenshot below.

Custom Notification Type → Equals → primary contact notification

  1. Under How many records to store select Only the first record.
  2. Under How to store Record Data select Automatically store all fields.

  1. Next step is to check whether the current contact is about to set as primary contact. Two paths get executed based on the value.
    1. Select (+) icon → Select Decision Element 

  1. Set the First outcome as Primary Contact - Equals - True (flow takes the first path, if the current contact is set as Primary Contact).

$Record > Primary Contacts →  Equals → True

  1. Next step is to check whether any of the existing contacts is set as primary.

Select (+) icon → Select Decision Element 

  1. Next step is to add an Assignment Element to uncheck all previous Primary Contacts.

\ Select (+) icon → Select Assignment Element

  1. Create a Variable to hold recipient Id

Data Type - Text

Object- Recipientid

  1. Select (+) icon → Add one more Assignment Element to add all modified contacts to a collection

  1. Update Unchecked Previous Contacts

                                                  

  1. Create a Formula Resource to capture the Primary Contact Name which is to be updated on Account Object.

Data Type - Text

API Name : formula for primary contact field in account object

Formula : {!$Record.FirstName}+' '+{!$Record.LastName}

  1. Here Updating the Primary Contact field in Account object.

                                                    

  1. Select (+) icon → Select Assignment Element to collect the Owner Ids of Current Primary Contacts.(This will be used to send Notifications)

                

  1. Select (+) icon → Select Send Custom Notification Element to send the notification

                                                                                          

  1. If the Primary Contact is False the flow will take the second path.

$Record > Primary Contacts →  Equals → False

$Record_Prior > Primary Contacts →  Equals → True

                                            

  1. Select (+) icon → Select Update Record Element to remove the Primary Contact Name on Account Object

  1. Select (+) icon → Select Assignment Element 

                                        

  1. Select (+) icon → Select Send Custom Notification Element to send the notification

WRAPPING IT UP

In this blog,  we have explained how to update the primary contact name in the account object automatically as well as manually using different ways.

Leave a Comment

Your email address will not be published

© 2024 Digital Biz Tech