Preface: this post is part of the SOQL: A Beginner’s Guide series.
You’ve probably already written SOQL, but you might not realize it yet!
Does this look familiar to you?
Yup – you can write SOQL queries in Data Loader! And yes, you can bypass the UI and simply type your query in the box!
But there’s still a better place to write SOQL, and it’s all the rage these days. I’m talking about Salesforce’s new tool called Workbench.
To begin writing SOQL queries, simply login to Workbench and go here:
Queries >> SOQL Query
Pro tip: Use the sfdc99 login so you can try out the examples posted on this site!
Writing SOQL queries in Workbench or Data Loader is useful to test your queries (I use it almost every day!), but the real power of SOQL comes when you mix it in with Apex, like in a trigger. I’ll show you guys how to do this very soon, but first, you need to learn the basics of the SOQL language!
Next post: Example: How to write a simple SOQL query
Hi David, thanks for another great post!
One of the tools I use every day as an Admin is the Salesforce Inspector (a Google Chrome extension). It offers a SOQL query editor with some predictive-text kinds of inputs. Sometimes it feels smoother than Workbench (I click once in the wrong place and all the fields I selected get removed from the Workbench query editor, for example).
Have you used these tools side by side, and do you have any thoughts on their comparison? Just wondering if I’m missing something with Workbench since I mostly use Inspector for export/import queries.
Thanks!
-Bryce
That sounds cool!
I don’t really have a preferred SOQL editor, they all work well enough for me. Sometimes I’ll use the dev console too.
I think you’ve found a great tool and by all means keep using it!
David
In Salesforce Developer Edition.
go to –>Developer Console. It has built-in Query Editor where we can do both SOQL and SOSL query.
Thanks for all the Amazing Tutorials David, I’m learning a lot from this site :)
I have a question with querying though and I’m not sure if it’s already been mentioned in some tutorials.
What’s the best approach when Querying multiple objects? Is there a Hierarchy like Parents first then child, then another child.. Something like that?
In my case, I wanted to update a Field on Object A from Object B that is a Lookup from Object X.
The Relationship looks like this.. Object A ===>>> Object X <<<=== Object B
Basically, both Object A and B are a lookup to the Object X.
I don't know how to start querying these so I could pass field value from Object B to Object A..
Hope you can give Idea about best approach for those kind of situation :)
Thanks!
Irvine
In case of relationship like Object A ===>>> Object X <<<=== Object B (Juntion Relation), we can normally query child object with attached parent field to update and refer from.
Consider FieldA from Object A needs to be updated from FieldB from Object B,
1. We can query both fields in query and try to update them like
List updateableRecords = new List();
for(ObjectX eachRecord : [Select ObjectA.FieldA, ObjectB.FieldB from ObjectX])
{
//Making Modifications in FieldA
eachRecord.ObjectA.FieldA = ObjectB.FieldB + ‘Modification’;
//Adding them to list for update
updateableRecords.add(eachRecord.ObjectA);
}
//Updating list
update updateableRecords;
2. We can also query Children of ObjectA with fields of ObjectB when you want to consider multiple children X of A to make field update
List updateableRecords = new List();
for(ObjectA eachRecord : [Select ObjectA.FieldA,(Select ObjectB.FieldB from ObjectX) from ObjectA])
{
//Making Modifications in FieldA
for(ObjectX eachChild : eachRecord.ObjectX)
{
eachRecord.FieldA += eachChild.ObjectB.FieldB;
}
//Adding them to list for update
updateableRecords.add(eachRecord);
}
//Updating list
update updateableRecords;
Connect me on shubhamsgupta306@gmail.com for any explanation.
Hey David, saw the video that you posted in your ‘About’ section and was very impressed. I have a question,I’m fairly new to Apex and salesforce(< month) and I have been reading a book :Apex-Do it now and its a good read but its a whole lot of theory(not fun like your site btw). I have reached the part where where we are now working on SOQL/SOSL and DML. the book doesn't specify where to write these queries, for the very first program it says use the Developer's account IDE which I have been playing around with but seems very simple as compared to Eclipse. I wanted to ask you if I am using Apex code with snippets of SOSL/SOQL queries and DML inserted in it, where do I do it?
P.S This sounds like a silly question but I am really at a loss here.
Keep reading through the chapters, I believe you’ll find your answers in Chapter 4-5!
Hi David — what setting specifically do I have to set to get the Bulk API CSV view option to work in Workbench. I have Googled and cannot find a solution as of yet! For example when perform a simple SOQL like below I get the following error message “UNKNOWN ERROR: FeatureNotEnabled: Async API not enabled”.
SELECT Name FROM Account LIMIT 10
Worked in my Workbench!
Workbench has a settings page if you haven’t already tried tampering with it:
https://workbench.developerforce.com/settings.php
Other than that I am at a loss!
David
Another great SOQL querying tool that I use on a daily basis is the free SoqlXplorer.
Unfortunately this is a Mac Only tool, but something that I find super handy:
http://www.pocketsoap.com/osx/soqlx/
Thank you John – looks very clean!!!