How to add comments in SOQL
Asked Answered
K

4

12

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 --, #, /*, //

Kep answered 23/11, 2012 at 11:2 Comment(0)
S
14

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)

Sterculiaceous answered 23/11, 2012 at 11:16 Comment(4)
Alas I'm using SOQL via the SOAP API. Thanks for the comprehensive answer!Kep
I'm not sure I understand your comment ;) They all use SOAP API, even the official Explorer. There's simply no "direct access to underlying Oracle DB" mode. If you want to experiment with queries before you put them in your app or something like that - it's definitely worth picking a better editor.Sterculiaceous
Looks like Real Force Explorer has move to BitBucket.Dicho
You can vote up this idea to get comment support added: success.salesforce.com/ideaView?id=08730000000cFqrAAEBellarmine
C
5

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'
Corpsman answered 15/7, 2015 at 14:16 Comment(0)
S
3

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.

Slot answered 18/4, 2014 at 18:20 Comment(2)
This is a terrible 'solution'/answer. This is not at all even relatively close to commenting and is only going to make queries more expensive.Gerhardt
I agree with Taylor. Commenting in Apex is enough.Dwight
D
2

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

Damsel answered 20/2, 2021 at 19:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.