My objective: I want to be able to programatically evaluate a formula expression in the same manner as SFDC does for formula fields. I wish to do this so that I can have formula parsing which is in line with SFDC standards.
Example Scenario I have an object type MyObject__c with field MyFormula__c. This field is a String (Text).
For one instance of this object, MyFormula__c = "1+1" (or a more complex scenario - "TotalCost__c - Discount__c")
I want a way that I can take this stored value of a formula, and that I can calculate it wrt my current instance of the object type. I want to do this at Apex runtime, not at SOQL-data retrieval. Can anyone help me with this? Is this even possible?
I've found a number of ways to tackle similar cases: Get a formula field's description at runtime, eval() via ToolingAPI / exception. etc...
I've found options like... Create an instance of the object in memory. Save it, then query it right back to get its calculated data. But nothing for calculating in Apex runtime.
Note I can create my own formula parser. I prefer not to in order to maintain standards and streamline UX / etc.