9
votes

Is it possible to put comments in SOQL?

The Force.com explorer doesn't support basic operations like undo/redo and I can't find any way to enter comments so experimenting with queries is painful.

I've tried all the usual suspects --, #, /*, //

4

4 Answers

11
votes

No, I don't think there's a way to use comments in SOQL. You can comment out pieces of queries you've issued in Apex though.

There are some tools that you might like more than the official Flash-based Explorer and the sluggish querying utility in Eclipse IDE.

My favorite is Real Force Explorer - has the searchable history of SOQL and Apex snippets, you can select the piece you want to run if you have several queries (like in Oracle's SQLDeveloper)...

I've heard some good stuff about BrainEngine too, didn't try it yet (basic version is free, cough up cash for more). The screenshots look tempting ;)

You might also like web-based tools like the official Workbench - if you're not a fan of providing the credentials in the officially hosted one you can download it and host it on your own machine.

Last but not least - JitterBit Data Loader got promoted some time ago to be listed in Setup pages. Haven't played with it either (might be it's just a data loader, not really suited for query editor tasks).

If you're SQL Server guy - have a look at DBAmp ($$$ again). I doubt it's the only connector to Salesforce, there have to be some more ODBC-like translation attempts. So you might be able to find a plugin for your favorite SQL editor after all.

(no, I'm not related to any of companies or projects behind these links)

3
votes

If you are writing inline SOQL inside of Apex, you can add Apex comments. Both block and single-line comments work.

You can verify this in the Execute Anonymous Window in the Developer Console:

List<Account> accounts = [
    SELECT ID From Account
    // single line comment
    WHERE Name = 'Test' /* block comment */
];

The Execution log shows that the comments are removed from the actual query:

SOQL_EXECUTE_BEGIN [1]|Aggregations:0|SELECT ID FROM Account WHERE Name = 'Test'
1
votes

I use SOQL Studio from VisualSoftwareSystems.net. It supports line comments and block comments as well as full syntax highlighting.

0
votes

OK, in SOQL you don't have the usual commenting mechanism. So now it's time for Boolean phantoms: appending an OR clause that can never be true, but contains comment info. Something like this:

SELECT id FROM Account WHERE Name = 'IBM' OR Name = 'This is the comment text explaining what this query is for'

This bit of hackery will slow down the query a little tiny bit...but if you simply must put the comment inside the SOQL (rather than at the end of the line invoking it), it does work.