LightningFlowComponents icon indicating copy to clipboard operation
LightningFlowComponents copied to clipboard

*{!Formula Evaluator}* - _({!EvaluateFormula_APEX})_ - {!Evaluator crashes if custom field name contains a number}

Open cdevelin opened this issue 1 year ago • 0 comments

Steps to reproduce

Steps to reproduce the behavior:

  1. Add a custom field to an object like Account which contains a numeric, e.g. 'Period_01'
  2. Using the Formula Builder screen component, create a formula to be evaluated which looks at that custom field, e.g.

IF ($Account.Period_01__c > 1, 123, 456)

  1. Test the output from the Formula Builder in the 'Evaluate Formula' invocable action
  2. Invocable action will fail with an error

Expected behaviour

Period_01__c should be recognised as a valid field on the object.

Actual behaviour

Error message in the Flow indicates the numerics in the field name are not handled, flow will crash with an error like:

An Apex error occurred: System.QueryException: No such column 'Period_' on entity 'Account'

Looking at the source code on GitHub, I believe the REGEX pattern matcher for field names is too restrictive, and only considers A-z , periods (.) and underscores (_) as valid characters in a field name.

This should be enhanced so that numbers are also valid in the context of a field name

i.e. Current pattern:

Pattern mPattern = pattern.compile('(?<!")[$!{]{1,2}[A-z_.]*[}]{0,}');

Perhaps should be:

Pattern mPattern = Pattern.compile('(?<!")[$!{]{1,2}[A-Za-z0-9_.]+(__c)?');

cdevelin avatar Sep 02 '24 06:09 cdevelin