I want to do something dynamic with an Apex method. I have some custom metadata records that contain an object and field definition. I want to inject the field value from the object into a custom formula (the formula would be stored on the custom metadata record as well, as text) at run-time.
The goal is to allow the custom metadata record to be as configurable as possible without requiring changes to the Apex implementation.
The formula body would look something like this: YEAR({!field-value}) < {!custom-metadata date field}
and the merge fields would be injected in the Apex method before evaluating the formula as a whole.
psuedo-code:
if field value is not null and a date:
put merge values into formula
evaluate formula
if formula is TRUE:
do foo()
Is it possible to do anything like this in Apex?