So i surfed a lot regarding this it but didn't found much relevant info,



Can I store my block of apex code as formula field and execute in apex

I want to know that can we use apex method in formula field to populate the same depending upon what apex method returns ?

so lets consider I have a global class and global method named as below respectively

emailProvider.getEmail(String a)

That takes a field value(Name) as an argument and returns email based on the argument

I want to use it as a formula field > emailProvider.getEmail(Custom_field__c).

I tried but getting error as Error: Unknown function emailProvider.getEmail Check spelling.


Now i know we can use formula for this instead of using Apex method but, (Custom_Field__c) is already a CASE formula which calls for even another CASE formula hence broke the limit.

I would really appreciate any help


1 Answer 1


No, you cannot use Apex in a formula field.

Formula fields are stored and evaluated in the database engine(s) that Salesforce uses in the background (which unless something has changed, is a combination of Oracle, HBase, and a few other things that I forget).

The database itself cannot run Apex (and I suspect it can't access the compiled JVM bytecode for a given Apex class either), so it cannot use Apex in its formulas.

You must log in to answer this question.

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