Search code examples
salesforceevalapex-code

Is there an eval() equivalent in apex/Salesforce?


I've looked into this, and it seems there is no directly related function available since Apex is so strongly typed, but I was wondering if anyone had found a workaround. I'm designing a credit risk object and my client wants to be able to insert expressions such as "150 + 3" instead of "153" when updating fields to help speed things up on her end. Unfortunately, I'm new to salesforce, so I'm having trouble coming up with ideas. Is this even feasible?


Solution

  • You could allow hand-entering of SOQL statements and then use dynamic SOQL to process them. But this would require a bit more than "150 + 3."

    Otherwise you could do this in JavaScript and pass the value back to Apex as an already calculated number.