3

I know we can use describe calls to identify if a field is a custom field or not. Similarly, is there any way we can check if a particular field is a formula field in apex? As per my knowledge and experience, i have never seen a method that can tell us that.. any help will be appreciated.

1 Answer 1

4

The DescribeFieldResult class has a method getCalculatedFormula(). If this method returns a non null value for a given field then that field is a formula field.

Update(based on the comments below): We can also use the isCalculated() method which returns true if the field is a custom formula field, false otherwise.

6
  • So it returns the formula or the calculated value? Apr 22, 2015 at 10:11
  • it would return formula (dont know why would they name the method like that!), the calculated value is anyway available on the field :) Apr 22, 2015 at 10:15
  • Rajiv - Yes I checked and it returns the complete formula. Thanks for the help. Apr 22, 2015 at 12:21
  • Instead of getCalculatedFormula(), you can also use isCalculated() method. This method returns true/false instead of complete formula. Apr 23, 2015 at 5:20
  • nice! i am sorry i completely overlooked that as I have been reading the actual formulas. Thanks for sharing though! :) Apr 23, 2015 at 5:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .