Search
Twitter
« Select all records created before/after ___ with SOQL | Main | Moxie Software Extends its Salesforce Integration »
Tuesday
May012012

Executing Anonymous Apex Inside Eclipse

One of the most underutilized programming techniques in Force.com is the ability to execute a snippet of apex code "anonymously". I know, it has a funny ring to it. Anonymous code is basically just a block of code that doesn't get stored inside Salesforce.com. This is nice, because often times you just want to try part of a method out or execute a SOQL statement without going through the hassle of adding it to a trigger or a class. 

This is a great technique to quickly evaluate or debug a statement of code on-the-fly. There are a couple of ways you can do this.

 

  1. Open up the Developer Console inside Salesforce
  2.  The executeAnonymousWeb services API call
  3. Inside Eclipse/Force.com IDE

I typically do this inside Eclipse so I thought I would quickly highlight how to do that and include a screenshot as a guide. When you have the Force.com IDE plugin installed in Eclipse, all you have to do is navigate to the Execute Anonymous tab. If you don't see the tab, make sure you've got the Force.com perspective open (opens by default when you create a new Force.com project). 

Inside the tab, you'll see a dropdown for the active project, a log category dropdown (apex code, apex profiling, callout, database, validation, workflow) and a log level slider.

Below those settings, you'll see a "Source to execute" textbox. Here is where you will actually type your code snippet. 

Now all you have to do is run it by clicking "Execute Anonymous". If there are any syntax errors, you'll see those below in the results window. If the code compiles, it will run and you'll see the output below. Don't get discouraged if the output looks a little verbose and hard to read. You can always adjust the slider over to the left and show less information. 

Execute Anonymous Apex in Eclipse (Click to Magnify)For the specifics on what type of code you can execute anonymously, check out the Salesforce.com documentation here.

 

 

 

 

 

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (1)

References allow you to track sources for this article, as well as articles that were written in response to this article.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.