Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Integer Class
Namespace
Usage
For more information on integers, see Integer Data Type.
Integer Methods
The following are methods for Integer.
format()
Signature
public String format()
Return Value
Type: String
Example
1integer myInt = 22;
2system.assertEquals('22', myInt.format());valueOf(stringToInteger)
Signature
public static Integer valueOf(String stringToInteger)
Parameters
-
stringToInteger:
Type: String
Return Value
Type: Integer
Examples
1Integer myInt = Integer.valueOf('123');A TypeException is returned if you attempt to convert a string to an invalid integer.
1String n = 'NotAnInteger';
2try {
3 Integer myInt = Integer.valueOf(n);
4} catch (TypeException ex) {
5 System.debug(LoggingLevel.Error, ex.getMessage());
6}valueOf(fieldValue)
Signature
public static Integer valueOf(Object fieldValue)
Parameters
-
fieldValue:
Type: Object
Return Value
Type: Integer
Usage
Use this method with the OldValue or NewValue fields of history sObjects, such as AccountHistory, when the field type corresponds to an Integer type, like a number field.
Example:
Example
1List<AccountHistory> ahlist =
2 [SELECT Field,OldValue,NewValue
3 FROM AccountHistory];
4for(AccountHistory ah : ahlist) {
5 System.debug('Field: ' + ah.Field);
6 if (ah.field == 'NumberOfEmployees') {
7 Integer oldValue =
8 Integer.valueOf(ah.OldValue);
9 Integer newValue =
10 Integer.valueOf(ah.NewValue);
11}