Work-Around For Conditional Auto-Number Field In Salesforce.

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

This can be done using record Triggered Flow.

Step 1. Create a text field on the Object.

  1. Go to object manager
  2. Click on subscriber object.
  3. Click on fields and relationship
  4. Click on New data type will be text
  5. Name the field “Subscriber unique ID”
  6. Select the Unique checkbox

Step 2. Create a Record trigger flow to populate this field

  1. Go to setup and search for Flows
  2. Click on flow and then create new.
  3. Select Record triggered flow
  4. Object = Subscriber
  5. Trigger the flow when a record is created
  6. Entry Condition = Null
  7. Optimize flow for = Fast field update
  1. Add decision Element after Start element
  2. Name the element “Check record Type”
  3. Name the first Outcome Partner
  4. Conditions should be {!$Record.RecordType.DeveloperName} = Partner
  5. We will create a new outcome for Customer
  6. For outcome= Partner we will create a get record element we will name it get partner
  7. Object will be a subscriber. Condition will be record type ID “partner record type ID”.How many records to store all records
  1. Add assignment element name the element = “Assign Partner count” 
  2. Create a number variable and name the variable “Partner Count”
  3. Set the variable 

Partner Count  > Equal Count > {!Get_partners}

  1. Select an update record element
  2. How to Find Records to Update and Set Their Values = Use the subscriber record that triggered the flow
  3. Condition None
  4. Subscriber_unique_ID__c = Create a new resource to update the field

Resource Type = Formula

Name = Partner ID 

Datatype = text



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}),


  1. We need to perform the same steps for customer outcome (Step M – Step U)
  1. Once completed the flow will look like this.

Y. Activate the flow and create test records to test the flow.

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.