Working With Conditions

Conditions allow to apply some logic conditionally. 

There are 4 types of conditions you can use:

  • Formula - use formula when you need to work with Source object, Variables, Current user, Environment, System data or Organization Settings.   
  • Query - use query when you need to work with SF objects.
  • Flow Step Status - build condition based on status of the specified process step
  • 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):

You can use Standard or Advanced config mode to create condition.

Standard Query config mode allows user to create condition using only process data source object fields, while selecting Advanced Query config mode adds Object picklist where user is to choose from the list of available objects (3):

  • Click "Add Condition" button
  • Fill blank fields with values
  • Add more conditions

Values can be of different types: 

  • Value - some static value
  • Field - values of the the fields of the Source object
  • Formula - compare with Merge fields of Context objects using formulas.

Provide condition logic expression if necessary (4):

Condition logic is build based on list of conditions user created.

If you don't 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 one needs to operate conditions Index (5) values. So {1} will represent Opportunity.Closed = TRUE condition, {2} will represent Opportunity.Fiscal_Quarter = 2 condition, etc.

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='[email protected]' 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 '[email protected]' 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 Using Functions.

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.

NOTE: Your custom Apex Class should implement WR_BPM.WorkflowCallApexRuleInterface Interface.

If run method returns 'true' conditions will not be met and action won't be executed. If action type is 'Rule' error message will be displayed and further actions won't be executed in case action is a part of Global Actions Group.

With the above setup global action will be executed (or will display error message if action type is 'Rule')  if {$Variables.callType} = 'check A' AND {$Variables.A} is not blank or if {$Variables.callType} = 'check B' AND {$Variables.B} = 'BBB'. Otherwise action won't execute.

public with sharing class WR_ApexRulesExpample implements WR_BPM.WorkflowCallApexRuleInterface
{
    public static Boolean run(sObject context, WR_BPM__Flow_Instance_Cursor__c flowInstanceCursor, String parameters)
    {
        Map<String, Object> params = (!String.isBlank(parameters) ? (Map<String, Object>)JSON.deserializeUntyped(parameters) : new Map <String, Object>());
   
        if(params.get('callType') == 'check A') 
        {
            if(String.isBlank((String)params.get('A')))
                return true;
            else 
                return false;
        }
        else if(params.get('callType') == 'check B' && params.get('B') == 'BBB')
            return false;
       
        return true;
    }
}
Working with Flow Step Status
  • Select condition Flow Step Status type
  • Process - Name of the Process you want to work with. 
  • Version - Version of the Process you want to work with.
  • Step - Step you want to work with.
  • Status - Select one or several step statuses.

Logic:

  •  "All must" - means that selected step should have one of the specified statuses in all active process instances to meet conditions
  • "At least one" - means that selected step should be in one of the specified statuses at least in one active process instance to meet conditions 

 

  • Add Conditions to filter records.

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.