Preface: this post is part of the SOQL: A Beginner’s Guide series.
View Chapter 2 quiz questions without the answers!
Chapter 2 Questions:
1. Why do 95% of triggers use SOQL?
2. What are the two words that appear in every SOQL statement?
3. Name at least three places you can write SOQL.
4. Which of these two statements will break and why?
SELECT Id FROM User WHERE IsActive = true
SELECT Id FROM User WHERE IsActive = ‘false’
5. Finish this statement which wants to query all Leads with an email address:
SELECT Id FROM Lead WHERE Email
6. Finish this statement, which wants to query all Accounts with names that start with an ‘A’
SELECT Id FROM Account WHERE Name LIKE
7. Write a query that gets all Opportunities with a Close Date in the future.
8. Which direction are these relationships? Upwards or downwards.
a. [Upwards] Contacts to Accounts
b. [Downwards] Accounts to Tasks
c. [Upwards] Opportunity Line Items to Opportunities
d. [Downwards] Accounts to Quote Line Items
e. [Upwards] Campaign Members to Accounts
f. [Upwards] Opportunity History to Accounts
9. When do you use __r instead of __c?
10. Write a query that gets a Contact’s Account owner’s username and their best friend as well as all related Tasks that were created in the last 90 days or have both a comment that contains the words ‘nutella’ and ‘krispy kreme’ and the Task creator’s title is populated. Oh yes – all the contacts have to weigh more than 120 pounds and have a best friend whose owner’s name ends in a ‘d’. No more than 100 records please… whew!
SELECT Id, Account.Owner.Username, Best_Friend__c, (SELECT Id FROM Tasks WHERE CreatedDate = LAST_90_DAYS OR (Description LIKE '%nutella%' AND Description LIKE '%kripsy kreme%' AND CreatedBy.Title != null) ) FROM Contact WHERE Weight__c > 120 AND Best_Friend__r.Owner.LastName LIKE '%d' LIMIT 100
‘%kripsy kreme%’ ? Shouldn’t it be ‘%krispy kreme%’. ;-)
I didn’t get everything exactly right on #10, but I came pretty close! I misunderstood where to pull Best Friend from the first time (I grabbed the Contact’s Account Owner’s best friend). I forgot my parentheses around the three criteria in the OR statement. And I forgot to add the LIMIT to 100 records.
I’m happy with that for my very first attempt at a complicated SOQL search ever!
Hi David,
I finished your SOQL session and after every part of tutorial I fell stronger and stronger in my knowledge!:) I hope it will end with DEV cert=) Thank you!
Woohoo!! Good luck on the cert!
When I run the first part of my query: SELECT Id, Account.Owner.Username, regalray1__Best_Friend__r.Name,(SELECT Id FROM Tasks WHERE CreatedDate= Last_90_Days OR (Description LIKE ‘%nutella%’ AND Description LIKE ‘%kripsy kreme%’)) FROM Contact
I am not hitting any errors in the query editor. But seeing the following error when running the query:
[object Object]: CreatedDate= Last_90_Days OR (Description LIKE ‘%nutella%’ AND ^ ERROR at Row:1:Column:126 field ‘Description’ can not be filtered in query call
Can you please help?
ooo the key is in the final part of the error message:
“‘Description’ can not be filtered in query call”
Basically it looks like you can’t have the Description field anywhere in your WHERE clause! The field is too big I believe (text area long) to filter on it.
Could anyone please tell me how to solve the Description filter problem that has been raised but not given solution how to resolve it. thank you in advance
For #5, can I also do
5. Finish this statement which wants to query all Leads with an email address:
SELECT Id FROM Lead WHERE Email LIKE ‘%@%’
Yup, that definitely also works too!
I got it too… :) Thanks David, all because of your support.
Good job Kruthi!!
Whoooohooooo… I got the query ALMOST correct in my first attempt (the format and the brackets and all) :D
was just unaware of the LAST_90_DAYS keyword and couple of field name which I am looking for the first time. You are too good David …. GOD BLESS YOU …!!!!
Go Nitin!!! woohooooo hahaha
Hi David ,
I have a lot of fun answering the questions! Would love it if you could add more questions! :)
Thanks!
Check out the webinar recordings, lots of great questions there! (won’t be up for a few more days)!