Newer Version Available
FormulaBuilder Class
Namespace
Usage
The context type that corresponds to the Apex class used in the builder withType() method 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()
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.
treatNumericNullAsZero(isNumericNullZero)
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
withFormula(formulaText)
Signature
public FormulaEval.FormulaBuilder withFormula(String formulaText)
Parameters
- formulaText
- Type: String
Return Value
withGlobalVariables(formulaGlobals)
Signature
public FormulaEval.FormulaBuilder withGlobalVariables(List<formulaeval.FormulaGlobal> formulaGlobals)
Parameters
- formulaGlobals
- Type: List<FormulaEval.FormulaGlobal>
- Uses values from the FormulaGlobal enum.
Return Value
withReturnType(returnType)
Signature
public FormulaEval.FormulaBuilder withReturnType(formulaeval.FormulaReturnType returnType)
Parameters
- returnType
- Type: FormulaEval.FormulaReturnType
- Uses values from the FormulaReturnType enum.
Return Value
withType(contextType)
Signature
public formulaeval.FormulaBuilder withType(System.Type contextType)
Parameters
- contextType
- Type: System.Type
- An instance of the Apex class type.
Return Value
withType(contextType)
Signature
public formulaeval.FormulaBuilder withType(Schema.SObjectType contextSObjectType)
Parameters
- contextSObjectType
- Type: Schema.SObjectType
- An instance of the SObject type.
Return Value
Example
1FormulaEval.FormulaInstance ff = Formula.builder()
2 .withReturnType(FormulaEval.FormulaReturnType.Boolean)
3 .withType(Account.SObjectType)
4 .withFormula('ISBLANK(Site)')
5 .build();
6
7Boolean siteIsBlank = (Boolean)ff.evaluate(new Account(Site='Test'));
8Assert.isFalse(siteIsBlank);