1. If you can solve a business need using either a workflow or a trigger, which should you use?
Always use a point-and-click solution (workflow) when possible!
- It’s easier for your team to create and maintain workflows
- Workflows are easier to find when debugging unexpected behavior in your org
- Workflows never break!
- You don’t have to write test classes
2. Is it possible to write a trigger directly in a production Salesforce org?
Not possible! All code must be written in a sandbox (any type) and deployed to production
3. What is Trigger.new and why is it so important?
Trigger.new is a special list of every record that has entered your trigger. You’ll see this variable in every trigger that’s written!
4. Which version of the field name do you reference in triggers? Field Label or Field/API Name?– Field Label: Favorite Color
– Field / API Name: Favorite_Color__c
– Field / API Name: Favorite_Color__c
Always use the Field/API name! Salesforce is more strict if an admin tries to change this name and it never has spaces, which makes it easier to read in code!
5. Is it possible to deploy code to production without writing a test class?
No – always write a test class! OK, technically, it is possible to deploy without a test class – but that method is actually more difficult and is never recommended.
6. How does your test class know which trigger to test?
Trick question – it doesn’t! Test classes must indirectly “trigger” triggers by doing actions that cause a trigger to fire – they never explicitly tell a trigger to run.
7. True or false. Developers should avoid using comments as much as possible in code since comments are ignored by Salesforce.
False! The more comments, the better! They’ll help you and other members of your team quickly understand what your code is doing.
8. At minimum, how many components must be added to a Change Set to deploy an Apex trigger?
Two – your trigger and your test class!
Chapter 1 Practice Trigger:
Write a trigger that transfers every new contact to an Account named “Sfdc99”!
Don’t forget the test class!
Write a trigger that transfers every new contact to an Account named “Sfdc99”!
Don’t forget the test class!
Your answers should look something like this:
trigger TransferContacton Contact (before insert) {
for (Contact contactInLoop : Trigger.new) {
// This ID will be different in your org!
contactInLoop.AccountId = '001i000000azqHs';
}
}
@isTest
public class TestTransferContact{
static testMethod void insertNewContact() {
Contact joe = new Contact();
joe.FirstName = 'Joe';
joe.LastName = 'Montana';
insert joe;
}
}
0 Comments