4

In our email to case functionality, we plan to introduce a feature via which the users will be able to input the Legacy Account Id which is numeric along with the Salesforce Account Id which is alphanumeric.

Is there any method available in Saleforce library that can indicate whether the data is a string or number ?

17

Yes. The Salesforce dev guide has a bunch of String methods for this kind of stuff.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm

Methods of interest are:

  1. isAlpha()
  2. isAlphanumeric()
  3. isNumeric()
| improve this answer | |
4

The String class had isNumeric(), isAlpha() and a number of other methods for checking the contents of Strings added in Winter '13.

The documentation for these methods can be found here :

isNumeric()

Returns true if the current String contains only Unicode digits; otherwise, returns false.

isAlpha()

Returns true if all characters in the current String are Unicode letters only; otherwise, returns false.

Example usage:

String num = '123';
System.debug(num.isNumeric()); // Writes TRUE to the debug log
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.