Skip to main content

Query Formatting

Query Formatting feature helps you format your SOQL/SOSL/DML Queries so you can easily understand and make sense of what they are doing.

To format, select the Query, right-click and click Format Query or click on the more actions menu in the toolbar and select Format Query menu option.

App will format the highlighted query and replaces with the formatted query.

Before

select Id, First_Active_Date__c, First_Actual_Date__c
from sitetracker__Activity__c
where sitetracker__Project__c in(
select id
from sitetracker__Project__c where sitetracker__Project_Status__c = 'Cancelled' and (Upsert_Id__c = null or (not Upsert_Id__c like 'a5I%')))
and (First_Active_Date__c != null or First_Actual_Date__c != null)

After

SELECT Id, First_Active_Date__c, First_Actual_Date__c
FROM sitetracker__Activity__c
WHERE sitetracker__Project__c IN (
SELECT id
FROM sitetracker__Project__c
WHERE sitetracker__Project_Status__c = 'Cancelled'
AND (
Upsert_Id__c = NULL
OR (NOT Upsert_Id__c LIKE 'a5I%')
)
)
AND (
First_Active_Date__c != NULL
OR First_Actual_Date__c != NULL
)

Query Format Options

Brobench has a few options to control how it formats the query. Those options can be accessed by clicking on More Actions Menu -> Query Options.

It shows the following dialog with format options.

OptionDefaultDescription
Print Width150Controls how wide the Query is formatted. If query fragment is bigger than this width, then it will try to wrap into new lines.
Uppercase KeywordstrueConverts the keywords to Uppercase. Or lowercase otherwise.
Clauses In New LinetruePlaces each of the Query clauses in new line. If false, then it tries to put multiple clauses in same line depending on the query width
Fields in New LinefalsePlaces each of the select fields in a new line. If false, then it tries to put as many fields as possible into a single line, and wrap if required.
Where Conditions in New LinetruePlaces each of the Where conditions in a new line. If false, then it tries to put as many as possible into a single line, and wrap if required.

Examples

SELECT UserId, COUNT(Id)
FROM LoginHistory
WHERE LoginTime > 2010-09-20T22:16:30.000Z
AND LoginTime < 2010-09-21T22:16:30.000Z
GROUP BY UserId
With Sub Queries and Multiple Conditions
SELECT Id, First_Active_Date__c, First_Actual_Date__c
FROM sitetracker__Activity__c
WHERE sitetracker__Project__c IN (
SELECT id
FROM sitetracker__Project__c
WHERE sitetracker__Project_Status__c = 'Cancelled'
AND (
Upsert_Id__c = NULL
OR (
NOT Upsert_Id__c LIKE 'a5I%'
)
)
)
AND (
First_Active_Date__c != NULL
OR First_Actual_Date__c != NULL
);
SOQL Chain Query
SELECT Opportunity.Id
FROM OpportunityContactRole
CHAIN
SELECT id
FROM account
WHERE id IN (:Opportunity.Id);
SELECT id, Pricebook2Id, Pricebook2.Name
FROM Opportunity
WHERE recordtype.DeveloperName IN ('Partner_Existing_Home', 'Partner_New_Home')
AND Pricebook2Id != NULL
LIMIT 1000
SELECT *
FROM task
WHERE whatid IN
(
'001Hp00002pB3MmIAK', '001Hp00003jJgSZIA0', '001Hp00003jJgSYIA0', '001Hp00003cF5SWIA0',
'001Hp00003cF4sFIAS', '001Hp00003cF4sGIAS', '001Hp00003cF4sHIAS', '001Hp00003cF4sIIAS',
'001Hp00003cF4sJIAS', '001Hp00003cF4sKIAS', '001Hp00003cF4sLIAS', '001Hp00003cF4sMIAS',
'001Hp00003cF4sNIAS', '001Hp00003cF4sOIAS', '001Hp00002f8dPQIAY', '001Hp00002f8dOLIAY',
'001Hp00002f8dOJIAY', '001Hp00002f8dOKIAY', '001Hp00002f8dOBIAY', '001Hp00002f8dOCIAY',
'001Hp00002f8dODIAY', '001Hp00002f8dOEIAY', '001Hp00002f8dOFIAY', '001Hp00002f8dOHIAY'
)
SELECT id, name, sitetracker__Item__c, sitetracker__Item__r.name, sitetracker__Status__c, System__c,
System__r.Status__c, (
SELECT id
FROM sitetracker__Field_Assets__r
)
FROM sitetracker__Field_Asset__c
WHERE sitetracker__Item__r.name = 'LA, Redeploy'
AND System__c != NULL
AND System__r.Status__c = 'Available for redeploy'
SELECT id, sitetracker__Status__c, sitetracker__Site__c, sitetracker__Site__r.Name, (
SELECT id, Name, Status__c, Warehouse_Location__c
FROM Systems__r
), {{systems__r.records[0].Warehouse_Location__c}} SystemLocation,
{{systems__r.records.map((it) =&gt; it.Status__c).join(', ')}} SystemStatus,
{{systems__r.records.map((it) =&gt; it.Id).join(', ')}} SystemIds,
{{systems__r.records.map((it) =&gt; it.Name).join(', ')}} SystemNames
FROM sitetracker__Field_Asset__c
WHERE id IN (:values)