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
Shilpa KambleShilpa Kamble 

How to get a next alphabet in alphabetical sequence in apex class?

How can I get the next alphabetical character in alphabetical sequence?
ex. I have  'A' letter, I want 'B' by using 'A'.
UC InnovationUC Innovation
Hi Shilpa,

Try looking into the Apex String Class (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm). I was able to do something like what you are asking for however its based on the ASCII numeric representations of the characters and doesnt necessarily give you the next letter if your letter is for example 'Z'. More on ASCII here (http://www.asciitable.com/) (use decimal values). Anyhow this is how I am able to get the 'next' character in alphabetical order. try something like this:
 
String character = 'A'; // From example
Integer[] ASCIINumericRepresentation = character.getChars(); // [65]
String nextCharacter = String.fromCharArray(new List<Integer> {ASCIINumericRepresentation[0] + 1}); // 66 = 'B'
system.assert(False, nextCharacter);

Hope this helps!

AM