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