Integer Class

Contains methods for the Integer primitive data type.

Namespace

System

Usage

For more information on integers, see Primitive Data Types.

Integer Methods

The following are methods for Integer.

format()

Returns the integer as a string using the locale of the context user.

Signature

public String format()

Return Value

Type: String

Example

integer myInt = 22;
system.assertEquals('22', myInt.format());

valueOf(stringToInteger)

Returns an Integer that contains the value of the specified String. As in Java, the String is interpreted as representing a signed decimal integer.

Signature

public static Integer valueOf(String stringToInteger)

Parameters

stringToInteger
Type: String

Return Value

Type: Integer

Example

Integer myInt = Integer.valueOf('123');

valueOf(fieldValue)

Converts the specified object to an Integer. Use this method to convert a history tracking field value or an object that represents an Integer value.

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

List<AccountHistory> ahlist = 
  [SELECT Field,OldValue,NewValue
   FROM AccountHistory];
for(AccountHistory ah : ahlist) {
  System.debug('Field: ' + ah.Field);
  if (ah.field == 'NumberOfEmployees') {
    Integer oldValue = 
      Integer.valueOf(ah.OldValue);
    Integer newValue = 
      Integer.valueOf(ah.NewValue);
}