+ Start a Discussion
Ben Merton 17Ben Merton 17 

How to refer to a text field to drive a formula?

I am trying to create a quite complicated set of objects to drive tax (similar to SAP).

The basic idea is that every tax should have a corresponding formula that defines how the tax is calculated when it is used on another object.  For example, if you may have a tax which is applicable on the base amount or it may be cumulative based on other taxes.

I therefore need to be able to use variables within a formula, but I want this to be configurable by a user.  The best idea I can think of is to use a simple text field in the record of the tax that defines the formulas for how this tax would work on a given object in standard Salesforce point-and-click formulas.

For example, in a text field (called Tax Formula) on the tax record, it would specify something like:

If (Object_Name__c=PO_Line_Item, 
TaxAmount__c=TaxRate__c*BaseAmount__c,
TaxAmount__c=TaxRate__c*(BaseAmount__c-WithholdingTaxAmount))

In the PO Line Item object, I would then want to be able to pull in this point-and-click code and run the formula whenever a record is created.

Is there a method / wrapper or some other type of class that allows the incorporation of standard point-and-click formulas to execute logic?

The alternative to this is that you have to create a custom formula field for every tax scenario for EVERY country that you plan to deploy in.

Any ideas?
Best Answer chosen by Ben Merton 17
pconpcon
There is not a way to dynamically generate this type of text field that then get resolved as a value on the object.  If you wanted to do this, you would have to write a parser in Apex and then parse this formula field and save the value yourself.  Alternately, you could write several Workflows based on the information in the record to do a field update.

All Answers

pconpcon
There is not a way to dynamically generate this type of text field that then get resolved as a value on the object.  If you wanted to do this, you would have to write a parser in Apex and then parse this formula field and save the value yourself.  Alternately, you could write several Workflows based on the information in the record to do a field update.
This was selected as the best answer
Ben Merton 17Ben Merton 17
Workflows - duh!  Thanks