Working with Conditions

Conditions allow to apply some logic conditionally.

There are 3 types of conditions you can use:

  • Query - use query when you need to work with SF objects.

  • Formula - use formula when you need to work with Source object, Variables, Current user, System data or Organization Settings.

  • Call Apex - use call apex if you need to apply some complicated logic, which can't be applied with above options.

Select "With Conditions" option (1) to start working with conditions:

Working with Query

Select Query condition type (2).

Advanced Query config mode adds Object picklist where user is to choose from the list of available objects.

Click "Add Condition" button:

  • Add conditions as needed

  • Fill blank fields with values:

    • Value - some static value

    • Formula - compare with Merge fields of Context objects using formulas.

Provide condition logic expression if necessary (4):

If user does not fill Logic field then all conditions are validated all at once so record that gets validated should meet all conditions.

To use conditions in Logic expression user needs to operate conditions Index values (5). So {1} will represent Opportunity.Closed = TRUE condition, {2} will represent Opportunity.Fiscal_Quater = 2 condition ect.

Each condition Index must be enclosed in curved brackets

Following operators can be used when creating logic based on list of indexed conditions:

OR evaluates if at least one of multiple values or expressions is true.

AND evaluates if two values or expressions are both true.

NOT[ expression that you want evaluated ] - Returns FALSE for TRUE and TRUE for FALSE.

( ) specifies that the expressions within the open parenthesis and close parenthesis are evaluated first. All other expressions are evaluated using standard operator precedence.

Examples:

Following condition will be met in case one of the listed clause return TRUE.

Following condition will be met in case opportunity is not "Closed", "Fiscal Quarter" value is 2 and either opportunity record "Has Line Items" or "Probability" value is greater than 80%.

Following condition will be met in case opportunity is in "Closed" state, "Probability" value is less than 80% and either "Fiscal Quarter" is not 2 or opportunity has no Line Items.

Creating complex query condition logic

{BR} operator is used to create WHERE part of Condition logic. Everything that goes after {BR} works the way clauses do after WHERE statement in Salesforce Object Query Language. Use SOQL SELECT Syntax after {BR} operator.

{BR} operator must go after base condition logic

Examples:

Following condition will be met in case opportunity is not in "Closed" state and "Fiscal Quarter" is 2 or both "Has Line Item" is TRUE and "Probability" is greater than 80%, and query will only include opportunity where CreatedBy.Email='user@email.com' or LastModifiedDate > YESTERDAY.

Following condition will be met in case opportunity is in "Closed" state and "Fiscal Quarter" is not 2 or both "Has Line Item" is FALSE and "Probability" is lower than 80%, and query will only include opportunity where "CreatedBy.Email" value is not 'user@email.com' or "LastModifiedDate" equals or greater than YESTERDAY.

Working with Formula

  • Select Formula condition type.

  • Select Context Object and Item and insert to your formula section.

See more on using Context Object at Working with Context objects. See more on using Functions in formula at Functions Library

Working with Call Apex

  • Select Call Apex condition type.

  • Select the Class Name in the drop-down. If you don't see your class in the drop-down, use Filter option.

  • Enter Parameters in a JSON format.

Your custom Apex Class should implement FLX_KB.KanBanInterfaces.ApiInterface interface.

Note: In Global Action pass required "methodName" and "parameters" params to custom apex when using FLX_KB.KanBanInterfaces.ApiInterface.

For condition with Call Apex type "methodName" parameter should be set to "Rule".

Below is an example of an apex class that is used to execute condition.

Call method should return boolean. If call method returns 'true' conditions will not be met and action won't be executed. With the above setup global action will always execute because we pass string as a "function" parameter value.

public with sharing class FLX_ApexConditions implements FLX_KB.KanBanInterfaces.ApiInterface {

    public Object call(String methodName, Object parameters)
    {
        Map<String, Object> params = (Map<String, Object>)parameters;
        if(params.get('function') != null) 
            return false;
        else
            return true;
    }
}

0 Comments

Last updated