Preface – This post is part of the Core Apex Tools series.
View Chapter 3 quiz questions without the answers!
Chapter 3 Questions:
1. What is ‘2’ + ‘2’?
2. What kind of data type is this value? true
3. Which of the following are sObjects?
– Account
– Task
– Opportunity Line Item
– Account Contact Role
– Contact History
– Price Book
4. What’s the difference between a List and a Set? What type is Trigger.new?
5. You have a list of “yummyDonuts” with values “chocolate glaze”, “cream filled”, and “jelly”, in that order. What does yummyDonuts[1] return? How about yummyDonuts[3]?
6. What is wrong with this dot notation: myContact.Best_Friend__c.Account.Opportunities.size()
7. What are two methods you can use on any List using dot notation?
8. What kind of variable would you need to store the output of this dot notation? myOpportunity.Account.Tasks
9. How many times would this loop run?
List
for (Integer i = 1; i < leads.size(); i++) {
// Drink a beer
}
10. When should you use == as a comparison operator and when should you use .equals()?
11. Select true or false for each of these scenarios. The opportunity is in stage ‘Closed Won’:
!opp.StageName.equals(‘Negotiation’) || !opp.StageName.equals(‘Closed Won’)
!(opp.StageName.equals(‘Open’) && opp.StageName.equals(‘Pending’))
!opp.StageName.equals(‘Demo’) && (!opp.StageName.equals(‘Open’) && !opp.StageName.equals(‘Closed Lost’))
opp.StageName.equals(‘Pending’) || (!opp.StageName.equals(‘Demo’) && opp.StageName.equals(‘Closed Won’))
12. What will my status be if I buy two dozen Krispy Kreme donuts?
String status;
if (donuts.size() > 20) {
status = ‘Heartburn’;
} else if (donuts.size() > 10) {
status = ‘Eazy Peazy’;
} else if (donuts.size() == 24) {
status = ‘King of Donut Land!’;
}
13. What’s wrong with this DML code?
Contact me = new Contact();
me.FirstName = ‘David’;
me.LastName = ‘Liu’;
update me;
14. Does this DML statement work?
List<Account> accounts = [SELECT Id FROM Account];
delete accounts;
Great work Devid,
thanks a lot..!)
Isn’t there a typo here
List leads = [SELECT Id FROM Lead LIMIT 99];
for (Integer i = 1; i < leads.size(); i++) { // Drink a beer }
Shouldn't first line be List leads = [SELECT Id FROM Lead LIMIT 99];
(and change ‘Drink a beer’ to ‘take a sip of your beer’. We don’t want anyone drinking 98 beers :)
Love your site
i have some difficulty understanding the standard salesforce objects, their fields and relations. i don’t have a marketing background, so a Line Item, Role, Price Book or History don’t mean much to me and i cannot clearly distinguish objects from fields. is there a resource available to explain these standard objects , their fields and relations?
I actually don’t know of any good tutorials explaining these. Hopefully someone else can point you to some!
sorry for my odd question. i did not start my career as an admin. i am a self-taught programmer, recently hired as a python developer. My company works with Salesforce and asked me to broaden my skill-set.
i have found a tutorial on CRM basics at trailhead that explains the standard objects.
https://developer.salesforce.com/trailhead/module/admin_intro_crm_basics
thanks a lot for the website. it is well explained and really helpful.
i would opt for extra challenges/exercises for SOQL and Apex. in the style of codingbat.com.
Hi David,
For Question No. 11 Last part I think the answer should be False as :
opp.StageName.equals(‘Pending’) || (!opp.StageName.equals(‘Demo’) && opp.StageName.equals(‘Closed Won’))
False OR (True AND False)
False OR False
False —–> Final Answer
Correct me if i am wrong
Thanks,
Shobhit
Here’s what I got!
False OR (True AND True)
Can you explain #11?
Also, how would I populate a field on a child record of contacts, with a field from the most recent opportunities they have.
Try using SOQL on the OpportunityContactRole object to get fields from the Contact or most recent Opportunity!
hi, can you please explain and number 11?
Try to replace each statement with true/false:
TRUE || FALSE
TRUE && FALSE || TRUE
etc etc
Hi David,
Can you please explain the answer for question 6.
I do understand we use the child relationship name for downward queries however I am not sure how are we using Opportunities in the below statement?
myContact.Best_Friend__r.Account.Opportunities.size()
So it goes like this:
(Upwards) Contact to Best Friend Contact
(Upwards) Best Friend Contact to Account
(Downwards) Account to Opportunities
An Account can have multiple Opportunities so it’s downwards – also we don’t use __r for Opportunities because it’s a standard relationship!
David
SELECT xyz, Account__r.Name FROM Order_Header__c.
here we used __r for account because it is custom relation ship
but in this “myContact.Best_Friend__r.Account.Opportunities.size()” we dont add__r for Account
can u please explain this
The first relationship is from Order Header (custom object) –> Account which is a custom relationship via a custom field
The second relationship is from Contact –> Account and that one is a standard relationship via a standard “Account” field =)
thank u
For your ques given as homework :)
Writing a trigger that creates a new opportunity every time an account is created
Is this right?
trigger insertOpp on Account (after insert) {
for(Account acc : Trigger.New)
{
opportunity opp = new opportunity();
opp.name = ‘Test opp’;
opp.CloseDate = Date.Today();
opp.Stagename=’Prospecting’;
opp.AccountId= acc.id;
insert opp;
}
}
We’ll done Sunny!!! Time to move on to more difficult challenges and chapters!!
Thanks David and great blog :)
Great explanation on sObjects! I’ve been trying to get my head wrapped around that concept and I think I finally got it!
David,
the link in the answer to number 7 is broken, i ‘think’ it should direct to this page?
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_list.htm
loving this site this afternoon, as a completely off topic to this particular post, did you fancy building a page of simple triggers that we could write with an ‘answers’ section so we can compare the code we write with what you believe to be the correct process?
my biggest failing of a budding developer is trying to identify a need for a trigger!
Thanks for letting me know Zak, the link is fixed!!
That’s a great idea – you guys need more homework! For now, try:
Writing a trigger that creates a new opportunity every time an account is created
I’ll grade you!
David
When I was looking at the answers I saw that What type is Trigger.new? question was not answered? Is this by design? Just wanted to bring it to your attention in case the answer decided to take a vacation on its own. :) Awesome work though!
You are totally right – the answer took a vacation!!! hahahaha
Trigger.new is a list =) It has a particular order!
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm
David
14. Does this DML statement work?
List accounts = [SELECT Id FROM Account];
delete accounts;
it will through an error , it should be List accounts = [SELECT Id FROM Account];
:-)
Great catch!!!! Fixed!
For 11) How is the second one true?
!(opp.StageName.equals(‘Open’) && opp.StageName.equals(‘Pending’))
True and False = False
!(False && False)
!(False)
True
Keep an eye out on the parenthesis =)
doh! Thanks for clarifying
Piggy backing on newsfdcdev question on #11. The first scenario is through me for a loop….
!opp.StageName.equals(‘Negotiation’) || !opp.StageName.equals(‘Closed Won’)
If the Stage is ‘Closed Won’, isn’t the statement above saying:
StageName does not equal Negotiation
or
StageName does not equal Closed Won
Since the Stage is ‘Closed Won’ wouldn’t the statement be FALSE?
As always…thank you for your dedication to help the rest of us!
I believe for an OR statement, just one of the tests has to be true for the statement to equate to true. So in the scenario, the first test is True (stage does not equal Negotiation) and the second is False (stage does equal Closed Won), but since one was True the statement is True. Hopefully David will verify this.
Thanks David for this site. I stumbled across this a couple weeks ago, and finally bit the bullet to learning Apex. So far this is great information, in an easy to understand presentation.
Thank you Matt and you are 100% correct about the OR statement!
Awesome site. Feel like I finally found a good explanation of Lists vs. Maps vs. Sets after scouring the interweb.
Appreciate the great explanations and plain speak for those of us that are new to the coding game.
Keep up the good work!
Coding isn’t as difficult as most make it seem – you can do it!!!
I always feel difficult to learn coding but after going through sfdc99.com i feel it is easy if we concentrate on it.
Harish, you are my brother. I wish you the best in your future development career =)