3

I want to create an apex parser when the user writes code in Apex (or selects objects and fields with required manipulations). Is there any API provided by Salesforce for Apex code parsing.

Ideally, I would want to create an interface similar to the one seen as a intermediate step of an Approval Process creation. The intermediate step is : Step 2. Specify Entry Criteria. Here when the user selects 'Formula Evaluates to True'. There is a text area box which appears with a 'Check Syntax' button.( Also additional arithmetic and logical functions are provided along with the object and the field lists).

Is there a way that this interface could be created on a custom Visual force page? And is it possible to parse the code written within the textarea box using an Apex Parser?

Salesforce Forumla Field Apex Parser

5
  • yes, it is possible and also complex too...still achievable!!
    – Bforce
    Commented Feb 10, 2014 at 9:00
  • You can use executeanonymous() method of the SOAP API to compile an apex code. Commented Feb 10, 2014 at 9:54
  • executeanonymous() can be used from an external source as a web service. I want to execute dynamic apex code from within apex. Is there any example of doing so? Commented Feb 10, 2014 at 10:42
  • You can callout from within Apex via Apex's HTTP support to the Execute Anonymous operation Saleforce provides to execute code, providing the user has the correct permissions. I stumbled apone this, wordgraphs.com/post/2151/Execute-anonymous-Apex-using-SOAP-API, though you can also these days use the Tooling API via REST, which will be lighter in terms of Apex code required. Let me know if this is something that would help and I'll elaborate in an answer via the Tooling API if you want. Commented Feb 10, 2014 at 11:14
  • Oh and yes, the Tooling API will allow you to parse (without deploying to the org) Apex code and will give you a Symbol Table back if you want to know more about the code, methods, properties etc. Commented Feb 10, 2014 at 11:16

2 Answers 2

1

Apex Code can't be stored in some place and executed. As apex code is first converted to java byte code. This link Running Apex script on the fly has a similar discussion.

0

You should take a look at Kevin Poorman's Apex Eval() idea. You could have people enter code on a VF page, store that, and then execute using the anonymous API described above.

But here, at least, Kevin and Andy have already done most of your work.

http://codefriar.com/2014/10/30/eval-in-apex-secure-dynamic-code-evaluation-on-the-salesforce1-platform/

You must log in to answer this question.

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