5. Fetch Related Contact Records
A. In the Flow canvas
B. Click the + icon under the Get Parent Account element. Scroll down and select the Get Records element.
C. On the Get Records screen, Add ‘Get Other Contacts of the Account’ as a Label. API Name will be auto-populated once you enter the Label.
D. In the Get Records for this Object section, Select Contact.
E. In the Filter Contacts Records section, Make sure ‘All Conditions are Met (AND)’ is selected under the Condition Requirements.
F. Add the AccountId (Account Id) in the Field. And the Operator should be ‘equals’.
G. In the Value Column, scroll down and select Account from 'Get_Parent_Account’ and then select Id (Account Id) from the Account fields
H. Keep sorting as Not Sorted
I. Select ‘All Records’ from the How Many Records section?
J. In the ‘How to store Record data’, select the option ‘Choose fields and let Salesforce do the rest’
K. Click Done
6. Loop Through Contacts To Get IDs
A. In the Flow canvas
B. Click the + icon under the Get Other Contacts of the Account element. Scroll down and select the Loop element.
C. On the Loop screen, Add ‘Loop through Contacts’ as a Label. API Name will be auto-populated once you enter the Label.
D. Select ‘Contacts from Get_Other_Contacts_of_the_Account’ as the Collection Variable.
E. Make sure the Direction is selected as ‘First Item to Last item’.
F. Click Done.
7. Contact Ids Assignment
A. In the Flow canvas
B. Click the + icon on the For Each section under the ‘Loop through Contacts’ element. Scroll down and select the Assignment element.
C. On the Assignment screen, Add ‘Assign Contact Ids’ as a Label. API Name will be auto-populated once you enter the Label.
D. In the Set Variable Values Section, under the variable Click ‘ + New Resource’. It will open a New Resource screen.
E. In the New Resource Screen, select Resource Type as Variable.
F. Set ‘ContactIds’ as the API Name.
G. Select Text as a Data Type and check the Allow multiple values (collection) checkbox.
H. Make sure the Flow availability options should be unchecked.
I. Click Done.
J. Once you get back to the Assignment screen. Select Add as an Operator.
K. In the value scroll down and select the ‘Current Item from Loop Loop_through_Contacts’ and then Select the Id (Contact Id) from the fields.
L. Click Done
8. Fetch Contact Share Records based on the Contact Ids
A. In the Flow canvas
B. Click the + icon on the After Last section under the ‘Loop through Contacts’ element. Scroll down and select the Get Records element.
C. On the Get Records screen, Add ‘Get Contact Share Records’ as a Label. API Name will be auto-populated once you enter the Label.
D. In the Get Records for this Object section, Select Contact Share.
E. In the Filter Account Records section, Make sure ‘All Conditions are Met (AND)’ is selected under the Condition Requirements.
F. Add the ContactId (Contact Id) in the Field. And the Operator should be ‘In’.
G. In the Value Column, scroll down and select ‘ContactIds’.
H. Click ‘+ Add Condition’.
I. In the new Condition add the ‘UserOrGroupId’ in the Field. Select the ‘Equals’ as an operator.
J. In the Value Column, scroll down and select ‘Account from Get_Parent_Account’ and then select OwnerId from the Account fields.
K. Keep sorting as Not Sorted
L. Select ‘All Records’ from the How Many Records section?
M. In the ‘How to store Record data’, select the option ‘Choose fields and let Salesforce do the rest’.
N. Select ContactId and UserOrGroupId under the Contact Share fields.
O. Click Done
9. Again Looping through Contacts
A. In the Flow canvas
B. Click the + icon under the Get Contact Share Records element. Scroll down and select the Loop element.
C. On the Loop screen, Add ‘Loop through Contacts to Check Share Records’ as a Label. API Name will be auto-populated once you enter the Label.
D. Select ‘Contacts from Get_Other_Contacts_of_the_Account’ as the Collection Variable.
E. Make sure the Direction is selected as ‘First Item to Last item’.
F. Click Done.
10. Filter Contact Share Records
A. In the Flow canvas
B. Click the + icon on the For Each section under the ‘Loop through Contacts to Check Share Records’ element. Scroll down and select the Collection Filter element.
C. On the Collection Filter screen, Add ‘Filter Current Contact Share Record’ as a Label. API Name will be auto-populated once you enter the Label.
D. Select ‘Contact Share from Get_Contact_Share_Records’ in the Collection section.
E. In the Apply Filter Condition add the ContactId in the Field. Select the ‘Equals’ as an operator.
F. For the Value, scroll down and select ‘Current Item from Loop_through_Contacts_to_Check_Share_Records’ and then select Id (Contact Id) from the Contact fields.
G. Click Done.
11. Assign Filter Share Records Count
A. In the Flow canvas
B. Click the + icon under the ‘Filter Current Contact Share Records’ element. Scroll down and select the Assignment element.
C. On the Assignment screen, Add ‘Set Filter Share records Count’ as a Label. API Name will be auto-populated once you enter the Label.
D. In the Select Variable Section, under the variable Click ‘ + New Resource’. It will open a New Resource screen.
E. In the New Resource Screen, select Resource Type as Variable.
F. Set ‘ContactShareRecordsCount’ as the API Name.
G. Select Number as a Data Type and make sure Allow multiple values (collection) checkbox should be unchecked.
H. Set Decimal Places to 0.
I. Keep Default Value empty.
J. Make sure the Flow availability options should be unchecked.
K. Click Done
L. Once you get back to the Assignment screen. Select Equals Count as an Operator.
M. In the Value scroll down and select the ‘Contact Share from Filter_Current_Contact_Share_Record’.
N. Click Done
12. Check if there are Previous Share Records Exist for the Current Contact
A. In the Flow canvas
B. Click the + icon under the ‘Set Filter Share records Count’ element. Scroll down and select the Decision element.
C. In the New Decision screen, Add ‘Does Contact share Record already Exists?’ as a Label. API Name will be auto-populated once you enter the Label.
D. In the New Outcome Tab, Set ‘Already Exists’ as a Label. API Name will be auto-populated once you enter the Label.
E. Under the Resource, select ContactShareRecordsCount and select Operator as ‘Greater Than’.
F. Add 0 as a Value.
G. Select the Default Outcome tab, and enter ‘Not Exists’ as a Label.
H. Done
13. Create A New Contact Share Record
A. In the Flow canvas
B. Click the + icon in the Not Exist section under the ‘Does Contact share Record already Exists?’ element. Scroll down and select the Assignment element.
C. On the Assignment screen, Add ‘Create Contact Share Record’ as a Label. API Name will be auto-populated once you enter the Label.
D. In the Select Variable Section, under the variable Click ‘ + New Resource’. It will open a New Resource screen.
E. In the New Resource Screen, select Resource Type as Variable.
F. Set ‘ContactShareRecord’ as the API Name.
G. Select Record as a Data Type and make sure Allow multiple values (collection) checkbox should be unchecked.
H. Set Contact Share as an Object.
I. Make sure the Flow availability options should be unchecked.
J. Click Done.
K. Once you get back to the Assignment screen.
L. Select ContactShareRecord in the Variable and then Select Contact Access Level field. Select Equals Count as an Operator.
M. Select ‘Read/Write’ in the Value.
N. Click '+ Add Assignment' and then again Select ContactShareRecord in the Variable and then Select Contact Id. Select Equals Count as an Operator.
O. In the Value scroll down and select the ‘Current Item from Loop_through_Contacts_to_Check_Share_Records’ and Select Id (Contact Id) from the Contact Fields.
P. Click '+ Add Assignment' and then again Select ContactShareRecord in the Variable and then Select User/Group Id. Select Equals Count as an Operator.
Q. In the Value scroll down and select the ‘Account from Get_Parent_Account’ and Select Owner Id from the Account fields.
R. Click Done.
14. Add the Contact Share Records to the Collection
A. In the Flow canvas
B. Click the + icon under the ‘Create Contact Share Record’ element. Scroll down and select the Assignment element.
C. On the Assignment screen, Add ‘Add Contact Share records’ as a Label. API Name will be auto-populated once you enter the Label.
D. In the Select Variable Section, under the Variable Click ‘ + New Resource’. It will open a New Resource screen.
E. In the New Resource Screen, select Resource Type as Variable.
F. Set ‘ContactShareRecords’ as the API Name.
G. Select Record as a Data Type and check the Allow multiple values (collection) checkbox.
H. Set Contact Share as an Object.
I. Make sure the Flow availability options should be unchecked.
J. Click Done.
K. Once you get back to the Assignment screen. Select Add as an Operator.
L. In the Value section select the ‘ContactShareRecord’.
M. Click Done.
15. Insert Contact Share Records
A. In the Flow canvas
B. Click the + icon on the After Last section under the ‘Loop through Contacts to Check Share Records’ element. Scroll down and select the Create Records element.
C. On the Create New Record screen, Add ‘Create Contact Share Records’ as a Label. API Name will be auto-populated once you enter the Label.
D. In the How many records to Create select Multiple
E. Select ContactShareRecords in the Record Collection.
F. Click Done.
Flow Overview:
_____________________________________________
Written by: Maham Hassan | Salesforce MVP
Maham Hassan is 2x Mom, Salesforce MVP, Director & Application Architect @ Cloud-1 & Check Automate, Co-Leader of Pakistan Dreaming, 11x Certified, Trailblazer Mentor, Community Group Leader & All Star Ranger.
Submissions reflect only the opinions of the user who made available the Submission and not the opinions of Salesforce, regardless of whether the user is affiliated with Salesforce, and may contain or constitute products, services, information, data, content and other materials made available by or on behalf of third parties ("Third Party Materials). Salesforce neither controls nor endorses, nor is Salesforce responsible for, any Third Party Materials, including their accuracy, validity, timeliness, completeness, reliability, integrity, quality, legality, usefulness or safety, or any applicable intellectual property rights. Any Submissions made available through any message board or forum in response to posted questions, or that otherwise purports to answer any questions, including any questions about Salesforce or Programs, are made available for your general knowledge only and should never be relied upon as answers to your specific questions (even if an answer is marked as a “best” answer or with any similar qualifications). You should always contact Salesforce support for answers to your specific questions. Salesforce has no control over Submissions, and is not responsible for any use or misuse (including any distribution) by any third party of Submissions.
If you have questions, tap into the wisdom of our entire Trailblazer Community here: https://trailhead.salesforce.com/trailblazer-community/feed
000395996

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.