Author: Rishabh Dubey
Requirement : On a custom object “Subscriber” we have two record types Customer and partner. We want an Auto-number field that will Assign a unique ID to the Subscriber record for Customer the ID will be C-0000 and for Partner P-0000.
Salesfore Provide Standard data type for Auo-number field however the Auto-number data-type does not allow us to add conditions.
There is an idea posted on Salesforce community regarding the same and below is the link of the idea
https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000A936tSAB
This can be done using record Triggered Flow.
Step 1. Create a text field on the Object.
- Go to object manager
- Click on subscriber object.
- Click on fields and relationship
- Click on New data type will be text
- Name the field “Subscriber unique ID”
- Select the Unique checkbox
Step 2. Create a Record trigger flow to populate this field
- Go to setup and search for Flows
- Click on flow and then create new.
- Select Record triggered flow
- Object = Subscriber
- Trigger the flow when a record is created
- Entry Condition = Null
- Optimize flow for = Fast field update
- Add decision Element after Start element
- Name the element “Check record Type”
- Name the first Outcome Partner
- Conditions should be {!$Record.RecordType.DeveloperName} = Partner
- We will create a new outcome for Customer
- For outcome= Partner we will create a get record element we will name it get partner
- Object will be a subscriber. Condition will be record type ID “partner record type ID”.How many records to store all records
- Add assignment element name the element = “Assign Partner count”
- Create a number variable and name the variable “Partner Count”
- Set the variable
Partner Count > Equal Count > {!Get_partners}
- Select an update record element
- How to Find Records to Update and Set Their Values = Use the subscriber record that triggered the flow
- Condition None
- Subscriber_unique_ID__c = Create a new resource to update the field
Resource Type = Formula
Name = Partner ID
Datatype = text
Syntax=
IF({!PartnerCount}=0,”P-00001″,
IF(LEN(TEXT({!PartnerCount}))=1,”P-000″+ TEXT({!PartnerCount}),
IF(LEN(TEXT({!PartnerCount}))=2,”P-00″+ TEXT({!PartnerCount}),
IF(LEN(TEXT({!PartnerCount}))=3,”P-0″+ TEXT({!PartnerCount}),
IF(LEN(TEXT({!PartnerCount}))=4,”P-“+ TEXT({!PartnerCount}),
“”)))))
- We need to perform the same steps for customer outcome (Step M – Step U)
- Once completed the flow will look like this.
Y. Activate the flow and create test records to test the flow.