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
Hope E.Hope E. 

Generation of an incremental alpha-numeric Id

Hi,
What is the best way to generate an incremental Alpha-numeric id. e.g => A000 - A001- A002 ..... A999 - B000 - B001 - ... AAB0 .... ZZZZ

Thanks

 

Muzammil BajariaMuzammil Bajaria
for sequesnce A000  -  Z999, please find the below code
 
public class alphabeticSequence {
    
    public void generateSequence(){
        integer upperLimit = 999;
        String sequence='';
        integer characterNumber = 0;
        // ADD ALBHABETS TILL Z
        List<String> Characters = new List<String> { 'A', 'B','C' };
            
            for(integer i=0;i<=upperLimit;i++){
                String temp = String.valueOf(i);
                if(temp.length()==1){
                    temp='00'+temp;
                }
                else if(temp.length() == 2){
                    temp='0'+temp;
                }
                else{
                    temp=temp;
                }
                sequence=Characters.get(characterNumber)+temp;
                system.debug(sequence);
                if(sequence.contains('999')){
                  // FOR SEQUENCE TILL Z CHANGE 2 TO 25 
                if(characterNumber == 2){
                        break;
                    }
                    else{
                        characterNumber++;
                        i=0;                 
                    }
                    
                }
            }
    }
    
}

For testing purpose i have just created sequence from A000 - C999. Change the variables according to your requirement.

Mark the answer as best answer if this solves your problem.

Thank you,
Muzammil Bajaria