[SalesForce] Overwrite value of Formula Field

I have a formula field which does some basic calculation. This field has been in the system from the time project went live. As an enhancement there are certain records whose values needs to be corrected – I have a batch class which uses this formula field and a hardcode value needs to be updated for these filtered records. How to do this?

Best Answer

Formula fields are formula fields; they dynamically calculate. You can't smash their values via APEX or Data Loader

However, what you can do is change the formula field to be something like this:

IF(NOT(ISBLANK(myOverrideField__c),
   MyOverrideField__c,  /* apply the override */
   .. the existing formula logic goes here /* use the existing calculation */
)

then, simply update the relevant Sobjects via Data Loader, the UI, or anonymous apex by updating the value of myOverrideValue__c to the value you want the formula field to be.

Related Topic