Boolean Class

Contains methods for the Boolean primitive data type.

Namespace

System

Boolean Methods

The following are methods for Boolean. All methods are static.

valueOf(stringToBoolean)

Converts the specified string to a Boolean value and returns true if the specified string value is true. Otherwise, returns false.

Signature

public static Boolean valueOf(String stringToBoolean)

Parameters

  • stringToBoolean: Type: String

Return Value

Type: Boolean

Usage

If the specified argument is null, this method throws an exception.

Example

Boolean b = Boolean.valueOf('true');
Assert.isTrue(b);

valueOf(fieldValue)

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

Signature

public static Boolean valueOf(Object fieldValue)

Parameters

  • fieldValue: Type: Object

Return Value

Type: Boolean

Usage

Use this method with the OldValue or NewValue fields of history sObjects, such as AccountHistory, when the field type corresponds to a Boolean type, like a checkbox field.

Example

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