All Projects → JitendraZaa → SFDCRules

JitendraZaa / SFDCRules

Licence: MIT license
Simple yet powerful Rule Engine for Salesforce - SFDCRules

Programming Languages

Apex
172 projects

Projects that are alternatives of or similar to SFDCRules

codeclimate-apexmetrics
ApexMetrics - Code Climate engine for Salesforce [DISCONTINUED use CC PMD instead)
Stars: ✭ 46 (+21.05%)
Mutual labels:  salesforce, apex
apex-dml-mocking
DML mocking, CRUD mocking, dependency injection framework for Salesforce.com (SFDC) using Apex
Stars: ✭ 38 (+0%)
Mutual labels:  salesforce, apex
apex-rollup
Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.
Stars: ✭ 133 (+250%)
Mutual labels:  salesforce, apex
Soqlx
SoqlXplorer is an awesome tool for developers using the Salesforce.com platform.
Stars: ✭ 220 (+478.95%)
Mutual labels:  salesforce, apex
timeline-component-lwc
This component enables timeline view for Salesforce Record history.
Stars: ✭ 18 (-52.63%)
Mutual labels:  salesforce, apex
universalmock
A universal mock class in Apex
Stars: ✭ 55 (+44.74%)
Mutual labels:  salesforce, apex
apex-rest-route
A simple framework for building Restful API on Salesforce
Stars: ✭ 75 (+97.37%)
Mutual labels:  salesforce, apex
Dreamhouse Sfdx
Salesforce Sample App part of the sample gallery. Real estate use case. Get inspired and learn best practices.
Stars: ✭ 164 (+331.58%)
Mutual labels:  salesforce, apex
Apex-Code-Conventions
Apex conventions and best practices for Salesforce Developers
Stars: ✭ 28 (-26.32%)
Mutual labels:  salesforce, apex
dreaminvest-lwc
Sample application for Lightning Web Components on Salesforce Platform. Part of the sample gallery. Financial services use case. Get inspired and learn best practices.
Stars: ✭ 41 (+7.89%)
Mutual labels:  salesforce, apex
Sfdx Mass Action Scheduler
🚀 Declaratively schedule Process Builder, Flows, Quick Actions, Email Alerts, Workflow Rules, or Apex to process records from Reports, List Views, SOQL, or Apex.
Stars: ✭ 200 (+426.32%)
Mutual labels:  salesforce, apex
R.apex
Functional utility library for Apex
Stars: ✭ 80 (+110.53%)
Mutual labels:  salesforce, apex
Haoide
Stop upgrade, most of features were delivered in https://github.com/xjsender/haoide-vscode
Stars: ✭ 194 (+410.53%)
Mutual labels:  salesforce, apex
apex-tmLanguage
Salesforce Apex Language syntax grammar used for colorization
Stars: ✭ 27 (-28.95%)
Mutual labels:  salesforce, apex
Apex Lambda
Functional programming for Salesforce Apex
Stars: ✭ 189 (+397.37%)
Mutual labels:  salesforce, apex
apex-mocks-stress-test
Testing out FFLib versus Crud / CrudMock
Stars: ✭ 47 (+23.68%)
Mutual labels:  salesforce, apex
Dreamhouse Lwc
Sample application for Lightning Web Components on Salesforce Platform. Part of the sample gallery. Real estate use case. Get inspired and learn best practices.
Stars: ✭ 136 (+257.89%)
Mutual labels:  salesforce, apex
Prettier Plugin Apex
Code formatter for the Apex Programming Language
Stars: ✭ 138 (+263.16%)
Mutual labels:  salesforce, apex
sfdc-error-playground
Lightning & Apex Error Playground
Stars: ✭ 30 (-21.05%)
Mutual labels:  salesforce, apex
ApexCallouts
A lightweight Apex library for making HTTP callouts. Works with remote site settings and named credentials.
Stars: ✭ 32 (-15.79%)
Mutual labels:  salesforce, apex

SFDCRules

Simple yet powerful Rule Engine for Salesforce - SFDCRules

SFDC Rule Engine

Read Blog post here

How to use SFDCRules

  • Define set of all allowed operators. We can move this step to some helper method to skip this step
  • Define set of binding values, which will replace variable or merge fields in rule
  • call eval() method of Rule class and it will return Boolean value indicating that rule evaluated is true or false

Example

//Define set of all allowed operators
//Mostly we don't need to change this, it can be added in setup method
Operations opObj = Operations.getInstance(); 
opObj.registerOperation(OperationFactory.getInstance('&&'));
opObj.registerOperation(OperationFactory.getInstance('==')); 
opObj.registerOperation(OperationFactory.getInstance('!=')); 
opObj.registerOperation(OperationFactory.getInstance('||'));
opObj.registerOperation(OperationFactory.getInstance('('));
opObj.registerOperation(OperationFactory.getInstance(')'));
opObj.registerOperation(OperationFactory.getInstance('<'));
opObj.registerOperation(OperationFactory.getInstance('<=')); 
opObj.registerOperation(OperationFactory.getInstance('>'));
opObj.registerOperation(OperationFactory.getInstance('>='));

//Define bindings, which will replace variables while
//evaluating rules		
Map<String, String>bindings = new Map<String, String>();
bindings.put('Case.OwnerName__c'.toLowerCase(), 'Jitendra');   
bindings.put('Case.IsEscalated'.toLowerCase(), 'false');  
bindings.put('Case.age_mins__c'.toLowerCase(), '62'); 

//Define rule
String expr  = 'Case.OwnerName__c == Minal || ( Case.age_mins__c < 75 && Case.IsEscalated == false )' ; 

//Initialize Rule Engine
Rule r = new Rule().setExpression(expr);   

//Evaluate rule with Binding values
Boolean retVal = r.eval(bindings) ;

//Check if expected result is correct
System.assertEquals(true, retVal);  

Capabilities, Considerations and Limitations

  • All Operators, variables and values must be separated by one or more spaces. Spaces are used to tokenize expression. We fix this by introducing some normalizing method however it would cost some CPU time.
  • Instead of writing Value1 == 100 OR Value1 == 200 we can use comma separated values. So, it can be written as Value1 == 100,200. Comma separated value is only supported for Integer and Decimal datatype, not for Strings.
  • Arithmetic operations like Value1 < 23* not supported.
  • Binding variables must be used as lower case.
  • Spaces in string values are not allowed. So, Value1 == ‘My Bad’ is not supported.
  • Code does not support short circuit execution of logic yet.
    • Example : Value1 == 100 && Value2 == 400 . In this case, if first condition fails, we should not evaluate second, as result will always be false.

Performance

We are talking about lots of string manipulations and comparison in Salesforce BRMS rule engine (SFDCRules). If its not used wisely, chances of hitting CPU limit are high. Lengthy expression size will result in using more CPU time. In Synchronous Apex, we get 10 sec before hitting CPU time limit error. Speaking about performance, around 7k expressions with 3 to 4 conditions can be evaluated before hitting 10 sec.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].