{"id":16981803,"url":"https://github.com/cesarparra/expression","last_synced_at":"2026-01-29T22:32:38.050Z","repository":{"id":185177684,"uuid":"672269316","full_name":"cesarParra/expression","owner":"cesarParra","description":"Evaluate formulas through Apex code.","archived":false,"fork":false,"pushed_at":"2025-03-11T12:56:31.000Z","size":14379,"stargazers_count":25,"open_issues_count":8,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T17:03:37.722Z","etag":null,"topics":["apex","aura","cloud","formula","formulas","lwc","salesforce","sfdx"],"latest_commit_sha":null,"homepage":"https://cesarparra.github.io/expression/","language":"Apex","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cesarParra.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"cesarParra"}},"created_at":"2023-07-29T13:50:25.000Z","updated_at":"2025-03-11T12:56:03.000Z","dependencies_parsed_at":"2023-12-15T21:43:57.673Z","dependency_job_id":"2066b64d-f94e-4acd-b204-9bab9339ad3d","html_url":"https://github.com/cesarParra/expression","commit_stats":{"total_commits":337,"total_committers":1,"mean_commits":337.0,"dds":0.0,"last_synced_commit":"9ca66f70bfc820feab1287da61e7b0e8b5daa49f"},"previous_names":["cesarparra/formula-evaluator"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesarParra%2Fexpression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesarParra%2Fexpression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesarParra%2Fexpression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesarParra%2Fexpression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cesarParra","download_url":"https://codeload.github.com/cesarParra/expression/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244885515,"owners_count":20526293,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apex","aura","cloud","formula","formulas","lwc","salesforce","sfdx"],"created_at":"2024-10-14T02:06:29.783Z","updated_at":"2025-10-14T12:10:42.619Z","avatar_url":"https://github.com/cesarParra.png","language":"Apex","funding_links":["https://github.com/sponsors/cesarParra"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"assets/expression_logo_dark.svg\"\u003e\n  \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"assets/expression_logo_light.svg\"\u003e\n  \u003cimg alt=\"Expression Logo\" src=\"assets/expression_logo_light.svg\" width=\"400\"\u003e\n\u003c/picture\u003e\n\nPowerful formula-syntax evaluator for Apex and LWC.\n\n\u003c/div\u003e\n\n# Features\n\n* Supports all the most important operators and functions available in Salesforce formulas\n* Support for lists and maps, including spread operator (`...`) support.\n* Automatically understands relationships and can extract data from child records\n* Comment support\n* String interpolations\n* Pre-built LWC component to evaluate Expressions in record pages and Experience Builder sites\n* And much more!\n\n# Examples\n\n## Basic Math Operations\n\n```apex\nObject simpleMath = expression.Evaluator.run('(1 + 1) * 10');\nSystem.debug(simpleMath); // 20\n\nObject respectsPemdas = expression.Evaluator.run('1 + 1 * 10 + 50 * 20 / 100 + (20 * 20 /10)');\nSystem.debug(respectsPemdas); // 61\n```\n\n## String Operations\n\n```apex\nObject simpleConcat = expression.Evaluator.run('\"👋 hello \" + \"there!\"');\nSystem.debug(simpleConcat); // 👋 hello there!\n\nId recordId = '001Oy00000GkWjfIAF';\nObject interpolation = expression.Evaluator.run('\"👋 hello ${Name}\"', recordId);\nSystem.debug(interpolation); // 👋 hello Acme Inc.\n```\n\n## Advanced Operations\n\n```apex\n// Calculating if a year is a leap year\nId recordId = '001Oy00000GkWjfIAF';\nObject result = expression.Evaluator.run('OR(\\n' +\n    '  MOD( YEAR( DATEVALUE(CreatedDate) ), 400 ) = 0, \\n' +\n    '  AND( \\n' +\n    '   MOD( YEAR( DATEVALUE(CreatedDate) ), 4 ) = 0,\\n' +\n    '    MOD( YEAR( DATEVALUE(CreatedDate) ), 100 ) != 0\\n' +\n    '  )\\n' +\n    ')', recordId);\nSystem.debug(result); // true\n\n// Determining the the region of an address\nId recordId = '001Oy00000GkWjfIAF';\nObject result = expression.Evaluator.run('IF(ISBLANK(BillingState), \"None\",\\n' +\n    'IF(CONTAINS(\"AK:AZ:CA:HA:NV:NM:OR:UT:WA\", BillingState), \"West\",\\n' +\n    'IF(CONTAINS(\"CO:ID:MT:KS:OK:TX:WY\", BillingState), \"Central\",\\n' +\n    'IF(CONTAINS(\"CT:ME:MA:NH:NY:PA:RI:VT\", BillingState), \"East\",\\n' +\n    'IF(CONTAINS(\"AL:AR:DC:DE:FL:GA:KY:LA:MD:MS:NC:NJ:SC:TN:VA:WV\", BillingState), \"South\",\\n' +\n    'IF(CONTAINS(\"IL:IN:IA:MI:MN:MO:NE:ND:OH:SD:WI\", BillingState), \"North\", \"Other\"))))))', recordId);\nSystem.debug(result); // South\n```\n\n## Using Lists and Maps\n\n```apex\nObject listExample = expression.Evaluator.run('[1, 2, 3]');\nSystem.debug(listExample); // (1 2 3)\n\nObject mapExample = expression.Evaluator.run('{\"key\": \"value\"}');\nSystem.debug(mapExample); // {key=value}\n```\n\n## Piping Complex Operations\n\n```apex\nId recordId = '001Oy00000GkWjfIAF';\nObject result = expression.Evaluator.run(\n    'ChildAccounts ' +\n        '-\u003e WHERE(AnnualRevenue \u003e 200) ' +\n        '-\u003e WHERE(NumberOfEmployees \u003e 10) ' +\n        '-\u003e MAP(Name)',\n    recordId);\nSystem.debug(result); // (Acme Inc. Acme Subsidiary)\n```\n\n## Declaring Custom Functions\n\n```apex\nString expr = 'fun factorial(n) =\u003e IF(n = 0 || n = 1, 1, n * factorial(n - 1));\\n' +\n    '\\n' +\n    'factorial(5)';\nObject result = Evaluator.run(expr);\nSystem.debug(result); // 120\n```\n\n# Documentation\n\n## Table of Contents\n\n- Introduction\n    - [Getting Started](https://cesarparra.github.io/expression/)\n    - [Installation](https://cesarparra.github.io/expression/docs/installation)\n    - [Try](https://cesarparra.github.io/expression/docs/try)\n- Usage\n    - [Evaluating Expressions](https://cesarparra.github.io/expression/docs/usage)\n    - [Accessing Contextual Data](https://cesarparra.github.io/expression/docs/accessing-contextual-data)\n    - [Configuring the evaluation](https://cesarparra.github.io/expression/docs/configuring-the-evaluation)\n- Language Features\n    - [Lists](https://cesarparra.github.io/expression/docs/lists)\n    - [Maps](https://cesarparra.github.io/expression/docs/maps)\n    - [Piping](https://cesarparra.github.io/expression/docs/piping)\n    - [Declaring Functions](https://cesarparra.github.io/expression/docs/declaring-functions)\n    - [Anonymous Functions](https://cesarparra.github.io/expression/docs/anonymous-functions)\n    - [String Interpolation](https://cesarparra.github.io/expression/docs/string-interpolation)\n    - [Querying Record Data](https://cesarparra.github.io/expression/docs/querying-record-data)\n    - [Referencing Org Data](https://cesarparra.github.io/expression/docs/referencing-org-data)\n    - [Comments](https://cesarparra.github.io/expression/docs/comments)\n- Standard Library\n    - [Operators](https://cesarparra.github.io/expression/docs/operators)\n    - [Functions](https://cesarparra.github.io/expression/docs/functions)\n- Advanced Usage\n    - [Custom Functions](https://cesarparra.github.io/expression/docs/custom-functions)\n    - [Apex Interoperability](https://cesarparra.github.io/expression/docs/apex-interoperability)\n    - [Providing More Context To Your Expressions](https://cesarparra.github.io/expression/docs/more-context)\n- Components\n    - [Getting Started with Expression Components](https://cesarparra.github.io/expression/docs/components/getting-started)\n    - [Accordion](https://cesarparra.github.io/expression/docs/components/accordion)\n    - [Alert](https://cesarparra.github.io/expression/docs/components/alert)\n    - [Avatar](https://cesarparra.github.io/expression/docs/components/avatar)\n    - [Banner](https://cesarparra.github.io/expression/docs/components/banner)\n    - [Button](https://cesarparra.github.io/expression/docs/components/button)\n    - [Avatars (Stacked)](https://cesarparra.github.io/expression/docs/components/stacked-avatars)\n    - [Features](https://cesarparra.github.io/expression/docs/components/features)\n    - [Form Builder](https://cesarparra.github.io/expression/docs/components/form-builder)\n    - [Formula](https://cesarparra.github.io/expression/docs/components/formula)\n    - [Hero](https://cesarparra.github.io/expression/docs/components/hero)\n    - [Input Text](https://cesarparra.github.io/expression/docs/components/input-text)\n    - [Nav Bar](https://cesarparra.github.io/expression/docs/components/nav-bar)\n    - [Logos](https://cesarparra.github.io/expression/docs/components/logos)\n    - [People](https://cesarparra.github.io/expression/docs/components/people)\n    - [Pricing Table](https://cesarparra.github.io/expression/docs/components/pricing-table)\n    - [Stats](https://cesarparra.github.io/expression/docs/components/stats)\n    - [Text Block](https://cesarparra.github.io/expression/docs/components/text-block)\n\nFor the full Expression language documentation,\nplease visit [cesarparra.github.io/expression/](https://cesarparra.github.io/expression/).\n\n---\n\n# Contributing\n\nContributions are welcome! Feel free to open an issue or submit a pull request.\n\n## Setup\n\nCreate a scratch org by running:\n\n```bash\nsf org create scratch -f config/dev.json -a Expression --set-default\n```\n\nPush the source to the scratch org:\n\n```bash\nsf project deploy start\n```\n\nAssign the `Expression Admin` permission set to the default user:\n\n```bash\nsf org assign permset -n Expression_Admin\n```\n\n### Debugging\n\nWhile debugging, you might find it helpful to see the generated AST for\na given expression.\n\nThe source code includes a `Visitor` implementation\nwhose sole purpose is to do this, `AstPrinter`. When enabled, it will\nprint the AST to the logs.\n\nYou can enable it by passing an `expression.Configuration` option to the `run`\nmethod with the `printAst` option enabled :\n\n```apex\nexpression.Configuration config = new expression.Configuration().printAst();\nObject value = expression.Evaluator.run('AND(true, false, 1=1)', config);\n// Outputs to the logs:\n// (AND true false (= 1 1))\n```\n\n## Running tests\n\nRun the tests with:\n\n```bash\nsf apex test run\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesarparra%2Fexpression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcesarparra%2Fexpression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesarparra%2Fexpression/lists"}