Loading

Salesforce Platform Flow: Count Contacts and Update Account Field

Udgivelsesdato: Oct 9, 2026
Beskrivelse

This article guides you through using a Salesforce Record-Triggered Flow to automatically count the total number of contacts directly linked to an account whenever a contact is created or updated. It also provides instructions on how to update the account with the accurate count of contacts.

Business use case: Track the number of active Contacts per Account for segmentation. When Contacts are added or removed, the Contact Count field on the Account updates automatically.

Løsning

This article explains how to use a Salesforce Record-Triggered Flow to count the contacts related to an account and store that count in a custom Contact Count field on the Account object. The steps cover creating the field, building the flow, and activating it.

Solution Overview

Step 1. Create a Custom Number Field in the Account Object

  1. From any page in Lightning, click the Gear icon in the top right corner. Select Setup and navigate to the Object Manager tab. Scroll down from the list of available objects until you find the Account. Once you see it, click it to select it.
  2. From the sidebar, click Fields & Relationships.
  3. Click New to create a custom field.
  4. Choose Number as the field Data Type and click the Next button.
  5. Enter the Field Name in the Field Label section as Contact Count. The Field Name populates automatically. Set the Decimal places to 0, and click the Next button.
  6. Set the Field-level security to determine whether the field should be visible for specific Profiles and Permission sets, and then click Next.
  7. Choose the Page layouts that should display the field and then click the Save button.

Step 2. Create a Record-Triggered Flow

  1. Click the Home tab.
  2. In the Quick Find box, enter and click Flows.
  3. Click the New Flow button.
  4. Select Record-Triggered Flow and click the Create button.

Screenshot of the New Flow dialog with Record-Triggered Flow selected in Salesforce Setup

Step 3. Set Up the Configure Start Window

  1. Set the object to Contact.
  2. Choose A record is created or updated in the Trigger the Flow When section.
  3. In the Set Entry Condition section, leave the Condition Requirements drop-down set to None.
  4. In Optimize the Flow for, select Actions and Related Records.
  5. Click Done.

Screenshot of the Configure Start window with the Contact object and A record is created or updated selected

Screenshot of the Configure Start window with Optimize the Flow for set to Actions and Related Records

Step 4. Add a Get Records Element

  1. On Flow Designer, click the + icon and select the Get Records element.
  2. Enter a Name for the element in the Label field (for example, Get Contacts). The API Name populates automatically.
  3. Set the Condition Requirements dropdown to All Conditions Are Met (AND). Add the following details as your Filter conditions:
    • Field: AccountId
    • Operator: Equals
    • Value: {!$Record.AccountId}
  4. In the How Many Records to Store section, select All records.
  5. In the How to Store Record Data section, select Automatically store all fields.
  6. Click Done.

Step 5. Create a New Resource

  1. Click the Toggle Toolbox located in the upper left corner of your Flow Builder canvas.
  2. Navigate to the Manager tab and click New Resource.
  3. Choose Variable from the Resource Type drop-down menu.
  4. Enter an API name (for example, ContactCount) and optionally provide a description for your variable.
  5. Select Number as the Data Type.
  6. Set the Decimal Places to 0.
  7. Set the Default value to 0.
  8. Click Done.

Screenshot of the Manager tab in Flow Builder with the New Resource button

Screenshot of the New Resource dialog with Variable as the resource type and Number as the data type

Step 6. Add an Assignment Element

  1. On Flow Designer, click the + icon and select the Assignment element.
  2. Enter a Name for the element in the Label field (for example, Assign Contact Count). The API Name populates automatically.
  3. In the Set Variable Values section, set the Variable field to {!ContactCount}, select Equals Count as the operator, and enter {!Get_Contacts} as the value.
  4. Click the Done button.

Screenshot of the Assignment element setting the ContactCount variable equal to the count of Get_Contacts

Step 7. Add the Update Records Element

  1. On Flow Designer, click the + icon and select the Update Records element.
  2. In the Label field, enter a Name for the element. The API Name populates automatically.
  3. In the How to Find Records to Update and Set Their Values section, select Specify conditions to identify records, and set fields individually.
  4. Set the object to Account.
  5. Set the Condition Requirements dropdown to All Conditions Are Met (AND) and add the following details as your Filter Conditions:
    • Field: AccountId
    • Operator: Equals
    • Value: {!$Record.AccountId}
  6. In the Set Field Values for the Account Records section, enter the details below:
    • Field: Contact_Count__c
    • Value: {!ContactCount}

Screenshot of the Update Records element filter conditions for the Account object

Screenshot of the Update Records element setting Contact_Count__c to the ContactCount variable

Step 8. Save and Activate Your Flow

Save and activate your flow. The setup is now complete.

About the Author

Written by: Tom Bassett | Forum Ambassador

Tom Bassett is a Solution Architect at Trigg Digital and has 5+ years of experience with the Salesforce platform. He aspires for customers to gain the most out of the CRM and spreads the Ohana culture by supporting the wider Trailblazer Community with new feature ideas and providing answers to questions posted. He co-leads the London Architect Community group and also contributes to Salesforce Ben as an expert Author.

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 purport 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

Vidensartikelnummer

000395389

 
Indlæser
Salesforce Help | Article