RSS

Tag Archives: Auto-Number Fields

Customizing Auto-Number Fields

Customizing Auto-Number Fields

Auto-number fields are fields where Salesforce saves an incremented number for you. It’s commonly known that you can specify a prefix in the field and the number of digits you want displayed, but did you know that Salesforce allows you to include date elements?


The General Format of the Auto-Number Field

I think it’s generally known that an auto-number field has a prefix section and a number section which produces a value something like this:

Job – 00001

In this example “Job – ” is the prefix and “00001” is the number.

I say “generally known” because when you create a custom object and select that you want the Name field to be an auto-number field, Salesforce gives you a suggestion with a prefix for how to format the value saved in that field.

What is slightly less obvious is that you can also specify a suffix which is any string of characters you choose to come after the auto-number portion of the value.

You tell Salesforce how you want the final field value to look by entering a “Display Format” (available with Auto-Number fields only).


The Display Format

The Display Format is like a word with a prefix and suffix where the word is the incremented number that Salesforce generates:

Prefix Auto-Number Suffix

The total length of an Auto Number field is 30 characters, 20 of which can be the prefix and/or suffix text, and 10 of which can be the number. That means is that you can play with adding up to 20 characters to the beginning and end of the auto-number.

It also means that there is a maximum number that can be generated–a number up to 10 digits or 9,999,999,999.


Specifying the Number Portion of the Format

The number portion of the field value is fairly straight forward:

  • It is designated by enclosing zeros between curly braces with the number of zeros indicating the number of characters the field should always display
  • The zeros indicate the minimum number of digit characters that are saved in the final field value
    • So a designation of {000} would add three or more digit characters to the final field value
  • As records are generated this portion of the final field value can expand to a maximum of 10 characters to hold larger numbers
  • The number portion of the Display Format is required with a minimum of one place-holder zero specified: {0}

Examples:

  • {0} – This is the minimum required number placeholder and will always display a number without any leading zeros
    • 1, 27, 392, 893827391
  • {0000} – This format would display numbers from 1 to 99 with leading zeros, and numbers greater than 99 without leading zeros:
    • 0003, 0041, 0178, 2693, 1928837492

One limitation is that the number cannot be displayed with any comma separation. For smaller numbers this isn’t a very big deal, but larger numbers will be just a run-on string of digits that look something like this:

8762039922


Specifying the Prefix and Suffix Portions of the Format

The prefix and suffix are any characters you choose. The sky’s the limit!

So anything you enter before the number format is part of the prefix, and anything you enter after the number format is part of the suffix.

Prefix – {0000} – Suffix


Adding Dates in the Prefix or Suffix

Salesforce has a provision for allowing you to add date values to the prefix and suffix portions of the auto-number. To do this you enclose day, month, or year specifiers between curly braces in one or more of these formats:

  • {DD} – show the two-digit day
  • {MM} – show the two-digit month
  • {YY} – show the two-digit year
  • {YYYY} – show the four-digit year

Examples:

  • {YYYY}-{MM}-{DD} {0000} – Creates: 2014-06-12 0008
  • TPS {0000} {MM}:{YY} – Creates: TPS 0213 06:14

Incidentally, the day, month, and year specifiers must be in capital letters (D, M, Y) and you must use two characters for the day and month (example, {D} and {M} will not work), and either two or four characters for the year..


Maximum Number

With auto-numbers you can specify what number you want Salesforce to begin with as long a your starting number is less than 1,000,000,000 or a maximum of 999,999,999.


Cheers!

Advertisements
 
Leave a comment

Posted by on June 13, 2017 in Fields

 

Tags: