Newer Version Available

This content describes an older version of this product. View Latest

FormulaBuilder Class

Contains methods to build and validate user-defined formulas.

Namespace

FormulaEval

Usage

For Developer Preview, all formula functions that you can include in validation rules are available to use with formulas in Apex. For details, see Formula Operators and Functions by Context.

The withType context type must be a global, user-defined Apex class. Any fields or properties that the formula references must also be global.

FormulaBuilder Methods

The following are methods for FormulaBuilder.

build()

Validates and returns the formula instance created using the FormulaBuilder methods.

Signature

public FormulaEval.FormulaInstance build()

Return Value

Type: FormulaEval.FormulaInstance

Returns an instance of the FormulaInstance object. If the formula validation such as field references, functions, or syntax, fails, the method throws a FormulaValidationException exception.

builder()

Creates an instance of the FormulaBuilder for configuring the formula, with input from the withFormula(formulaText), withReturnType(returnType), and withType(contextType) methods.

Signature

public static FormulaEval.FormulaBuilder builder()

Return Value

Type: FormulaEval.FormulaBuilder

treatNumericNullAsZero(isNumericNullZero)

Optional. Indicates whether a null for a numeric data type is treated as zero while evaluating the formula with the build() method.

Signature

public FormulaEval.FormulaBuilder treatNumericNullAsZero(Boolean isNumericNullZero)

Parameters

isNumericNullZero
Type: Boolean
If true, null for numeric is treated as zero. The default value is false.

Return Value

Type: FormulaEval.FormulaBuilder

withFormula(formulaText)

Required. Sets the formula expression that the build() method uses to create the formula instance.

Signature

public FormulaEval.FormulaBuilder withFormula(String formulaText)

Parameters

formulaText
Type: String

Return Value

Type: FormulaEval.FormulaBuilder

withGlobalVariables(formulaGlobals)

Optional. Sets the list of global variables that can be referenced in the formula expression created with the build() method.

Signature

public FormulaEval.FormulaBuilder withGlobalVariables(List<formulaeval.FormulaGlobal> formulaGlobals)

Parameters

formulaGlobals
Type: List<FormulaEval.FormulaGlobal>
Uses values from the FormulaGlobal enum.

Return Value

Type: FormulaEval.FormulaBuilder

withReturnType(returnType)

Required. Sets the formula output data type for the formula instance created with the build() method.

Signature

public FormulaEval.FormulaBuilder withReturnType(formulaeval.FormulaReturnType returnType)

Parameters

returnType
Type: FormulaEval.FormulaReturnType
Uses values from the FormulaReturnType enum.

Return Value

Type: FormulaEval.FormulaBuilder

withType(contextType)

Required. Sets the Apex type that corresponds to the Apex class used with the build() method.

Signature

public FormulaEval.FormulaBuilder withType(System.Type contextType)

Parameters

contextType
Type: System.Type
An instance of the Apex class defined against an Apex object or SObject.

Return Value

Type: FormulaEval.FormulaBuilder