function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Trigger to pull 18 digit Account ID

Hey everyone-


I need to create a field within the account object that holds the account records ID.  I can get the 15 digit ID very easily via a formula field, but unfortunately I need to get the full 18 digits.  Has anybody made a trigger like this in the past?  If so can you please share your code??  Thank you very much in advance.



Shashikant SharmaShashikant Sharma

Use this example for your case in trigger


You can directly save it in formula field return type text  like using this formula :






Ankit AroraAnkit Arora

I have a bit simplified code I guess, please visit :


//Our 15 Digit Id
String id = '00570000001ZwTi' ;

string suffix = '';
integer flags;

for (integer i = 0; i < 3; i++) {
          flags = 0;
          for (integer j = 0; j < 5; j++) {
               string c = id.substring(i * 5 + j,i * 5 + j + 1);
               //Only add to flags if c is an uppercase letter:
               if (c.toUpperCase().equals(c) && c >= 'A' && c <= 'Z') {
                    flags = flags + (1 << j);
          if (flags <= 25) {
               suffix = suffix + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.substring(flags,flags+1);
               suffix = suffix + '012345'.substring(flags-25,flags-24);

//18 Digit Id with checksum
System.debug(' ::::::: ' + id + suffix) ;



Ankit Arora

Blog | Facebook | Blog Page


Thank you both, this is very helpful.

Ankit AroraAnkit Arora

Cool! I would suggest you to mark the post as solution so others may get benefit.



Ankit Arora

Blog | Facebook | Blog Page

Rahul SharmaRahul Sharma

Nice work Ankit,


I was just wondering how its done, could you please explain the code.


Thanks a lot bro.