Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
com.salesforce.formula:formula-engine
Advanced tools
Implementation of a formula engine in the "salesforce" style, which supports the standard force.com syntax, support for generation of sql and javascript, and extensibility for reuse as an email templating language.
An implementation of a reusable formula engine with javascript & sql generation along with Salesforce-approved syntax.
For the end-user documentation of the formula engine's functionality, please see the end-user facing documentation.
In order to implement this formula engine in your application, you need to
Class
that represents the type along with a FormulaDataType implementation
that's used manage type conversion and error handling. You'll need something like MockFormulaDataType in your application,
but if you're only handling strings, it can be simple.FormulaFactoryImpl
, probably adding FieldReferenceCommandInfo
and DynamicReference
to the commands,
along with whichever implementations of FormulaCommandInfo you need for your application.MockLocalizerContext
included in the test code, set the LocalizerFactory
at the start of your application. You may want to override
FormulaValidationHooks.getLocalizer()
to return the same localizer.FormulaTypeSpec
implementation that returns a valid getDefaultProperties, probably as an Enum.
If you want different type of formulas in your application, make it an Enum like in MockFormulaType
. If you want
javascript generated for mobile/offline use, you'll need to override that here.FormulaContext
that represents your data providers. Make sure your root context implements
getProperty
, setProperty
, getFormulaReturnType
, isFunctionSupported
as they will be called in all circumstances.
Extending BaseCompositeFormulaContext
is probably easiest for your Root/Default formula context. Then
addContextProvider
for the various stuff you includeContact.Account.Name
, but each formula context will get a chance
to return the field at each point of the hierarchy, so you can override the resultsFormulaEngine.getFactory().create(...)
and then reuse that
with different runtime contexts when you call getFormula().evaluate(...)
. This lets you reuse the FormulaInfo
multiple times, as formula parsing is somewhat expensive. If you want to handle the type conversions yourself,
call evaluateRaw
, not evaluate
on the formulas.$F
.
See FormulaJsTestUtils.getFunctionScript()
for the examples. You'll also want to load the included decimal.js
if you want high precision decimals client side, suitable for currencies.UnsupportedOperationException
to minor differences in corner cases.FAQs
Implementation of a formula engine in the "salesforce" style, which supports the standard force.com syntax, support for generation of sql and javascript, and extensibility for reuse as an email templating language.
We found that com.salesforce.formula:formula-engine demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.