How can we help?

You can also find more resources in our Help Center.

299 terms

Salesforce Certified Platform Developer I - Apex

Describe differences between Apex and traditional Programming Languages like Java.
1.) Traditional Programming Languages are fully flexible, and allow you to tell the system to do just about anything. Apex is governed, and can only do what the system allows.
2.) Apex is case-insensitive
3.) Apex is on-demand, and is compiled and executed in the Cloud (i.e. on the server)
4.) Apex requires unit testing for deployment into a Production environment
5.) Apex is not a general-purpose Programming Language. It can only be used on the platform.
What are the two primary components of Apex code?
Apex Classes and Apex Triggers
What is an Apex Class?
An Apex Class is a template or a blueprint from which Apex objects are created.
What is an Apex Trigger?
A procedure that automatically executes during a DML operation.
What are the three types of FOR() loops that Apex code supports?
1.) Traditional FOR() loops
2.) List Iteration FOR() loops
3.) SOQL FOR() loops
What are the three types of Collection data types in Apex code?
1.) Lists
2.) Maps
3.) Sets
What are Collections used for in Apex code?
Collections are used to store groups of elements, such as primitive data types, or sObjects.
Where are the three areas where you can develop Apex code?
1.) The IDE
2.) The Developer Console
3.) The Setup menu
What conditional statements does Apex support?
What conditional statements are not supported by Apex?
1.) case
2.) switch
What is the sObject data type?
The sObject data type is a generic data type that is the parent class for all standard and custom objects in Apex.
What are two data types that are unique to Apex?
1.) sObject
2.) ID
What is a List?
A List is an ordered collection of elements of a single data type. Elements added to a List are assigned an implicit index, and therefore, Lists can contain non-unique values (i.e. elements can be duplicated within a List).
What is a Set?
A Set is an unordered collection of unique elements. There are no indexes assigned to elements in a Set, and therefore, elements in a Set much be unique.
What is a Map?
A Map is a collection of key-value pairs. Keys must be unique, but Values can be repeated. With Maps, we supply the index, unlike Lists, where the index is automatically applied when an element is added.
What is a common use case for Lists?
Lists are commonly used to hold the results of a SOQL query.
What is a common use case for Sets?
Sets are commonly used to store values used to filter data queried by SOQL.
What is a common use case for Maps?
Maps are commonly used as a cache of records that can be accessed by key/ID.
Are Apex Arrays the same as Java Arrays? Why or why not?
While Apex Array notation seems the same as Java Array notation, they are internally different. Apex Arrays can be dynamically resized, while Java Arrays cannot be dynamically resized.

//Array notation
Account[] accounts = new Account[] {acc1,acc2,acc3};

//List notation
List<Account> accounts = new List<Accounts>;
Are Lists also Arrays?
No. Lists are not Arrays, but they can be syntactically referenced as Arrays.
How can you iterate over a Map?
First retrieve the key set by using the Map.keySet() method. Then, use a FOR() loop to iterate through the key set to access and work with each value in the Map.
What do classes consist of?
Methods and Attributes
What is an inner class?
A class within another class
Does the name of a class need to begin with a capital letter?
No. But, it is recommended that this be done. More specifically, it is recommended that the Java notation be followed.
What are some ways that Apex classes are different from Java classes?
In Apex:

1.) Inner classes can only be nested one level deep
2.) Static methods and attributes can only be declared in a top-level class definition (i.e. an "outer class").
3.) The system-defined "Exception" class must be extended in order to create new exception classes.
What are two ways that an Apex class can be created from the UI
Under Setup > Develop > Apex Classes...

1.) Click the "New" button to enter the code manually.
2.) Click the "Generate from WSDL" button and upload a WSDL file.
What are the three access modifiers for an Apex class?
1.) Public
2.) Private
3.) Global
What are some optional definition modifiers for an Apex class?
1.) with sharing
2.) without sharing
3.) virtual
4.) abstract
What is the format for a class definition?
[access modifier] [definition modifier (optional)] class [class name] [implements (optional)] [extends (optional)] { //class body }
Where is a global class accessible?
A global class is accessible within and outside of the org or namespace.
When is the global access modifier mainly used?
The global access modifier is mainly used when:

1.) You want to create an email service or a web service.
2.) You want to allow an API call to appExchange code or a managed package that is published to the appExchange.
3.) You want to allow users from outside the namespace to access the code.
What happens when you use the public access modifier?
The class will be accessible throughout the application, org, or namespace that comprises the class.
What happens when you use the private access modifier?
When you use the private access modifier in a class definition of an inner class, the inner class is only accessible to the outer class.
What is the default access level for top-level classes, also called "outer classes"?
There is no default access level for top-level classes. The access modifier must be specified.
What access modifiers can be assigned to a top-level class?
1.) global
2.) public
What is the default access level for inner classes?
What is the default access modifier for all methods and attributes across all Apex classes?
True or False: All Apex code executes in the system mode.
False. All Apex code, with the exception of anonymous blocks, executes in the system mode.
What happens when the code executes in system mode?
The code ignores all CRED permissions on objects and field level security, and ignores all record sharing privileges.
What happens when you apply the "with sharing" definition modifier to a class?
Record level sharing privileges are enforced within the class. For example, a SOQL query executed within a "with sharing" class will only return the records to which the user has at least Read Only access. Similarly, users can only update records to which he/she has Read/Write access.
True or False: A "with sharing" class still ignores all CRED permissions on objects and field level security.
What happens when you apply the "without sharing" definition modifier to a class?
Sharing model access will be ignored. This means that when a user queries the database, the record level read or edit restrictions are not taken into account. Also referred to as "running in system mode".
What happens when neither the "with sharing" or "without sharing" definition modifiers are specified for a class?
The sharing model access is enforced. That is to say, the "with sharing" behavior is the default.
What happens if a class is called from a class that does not have sharing enforced?
Sharing is not enforced for the called class as well.
What is an interface?
An interface is a class that only includes method signatures. The methods are not implemented in the interface. Another class must be created to supply the implementation.
True or False: You do not have to complete the implementation of all the methods of an interface class in order to implement the interface.
What is the syntax of an attribute?
[access modifier] [data type] [attribute name] [initialization]

Ex. public Integer myInt = 0;
What is the value of an attribute if it is not initialized?
What does it mean to "overload" a method?
To overload a method means to declare multiple methods with the same name, but with different signatures.
What is the syntax for a method?
[access modifier] [return type] [method name] [parameters] { //method definition... }
Is the access modifier portion of a method declaration optional?
What are four access modifiers for methods and attributes?
1.) public
2.) private
3.) protected
4.) global
What can access a protected method or attribute?
Only instance methods and member attributes can access a protected method or attribute.
True or False: A global method or attribute can be declared within a private class.
False. If you declare a global method or attribute within a class, that class must also be declared as global.
Describe a static method.
Static methods do not require an instance of an object to run. They are accessed through the class itself. They are generally utility methods that do not depend on an instance of the class.
Give an example of a standard static method.
Describe static attributes.
Static attributes are accessed through the class itself, and not through an instance of the class. They are used to store data that is shared within the class. All instances of the same class invoked in the same context share the same copy of static attributes. They can be used to set recursive flags to prevent recursive logic from performing the same operation more than once.
What is a constant?
Constants are attributes that can be assigned a value only once. Constants are defined using the "static" and "final" keywords.
When can a constant be initialized?
Either in the declaration itself, or via a static initializer method, if the constant is defined within a class.
What is the syntax for instantiating a class object?
[class name] [object name] = new [constructor()];
True or False: To work with non-static methods or attributes within a class, you do not need to create an instance of the class.
What is a constructor?
A constructor is a special method that is used to create an object out of a class definition.
Do constructors have a return type?
True or False: Classes have a default, no argument, invisible public constructor ONLY if no explicit constructor is defined.
True. The default constructor goes away when you define a custom constructor.
What is the "this" keyword used for?
The "this" keyword is used to represent the methods and attributes of the current instance of the class.
What are the two ways that you can use the "this" keyword?
1.) with dot notation
2.) with constructors
What are two examples of system-delivered classes?
1.) System
2.) UserInfo
What are limit methods?
Limit methods are methods that can be used to help manage governor limits, and can be used for debugging and printing messages.
True or False: There are two versions of each limit method.
True. The first version returns the amount of a resource used, and the second version returns the amount of a resource left.

Ex. getQueryRows
Ex. getLimitQueryRows
What are the three process classes?
1.) ProcessResult
2.) ProcessSubmitRequest
3.) ProcessWorkItemRequest
What is the ProcessResult class used for?
ProcessResult is used to process the results from a workflow process.
What is the ProcessSubmitRequest class used for?
ProcessSubmitRequest is used to submit a workflow item for approval.
What is the ProcessWorkItemRequest class used for?
ProcessWorkItemRequest is used to process an item after it has been submitted
Describe the format of Parent-to-Child relationships.
Parent-to-Child relationships use plural version of the child object name.

Ex. Contacts

If the relationship is a custom relationship, the relationship is appended with "__r"

Ex. Interviewers__r
Describe the format of Child-to-Parent relationships.
Child-to-Parent relationships use the singular version of the parent object name.

Ex. Account

If the relationship is a custom relationship, the relationship is appended with "__r"

Ex. Position__r
True or False: Relationships in Apex are written in dot notation.

Ex. myRecord.Position__r.Status__c;
Describe the three parts of a relationship field.
1.) ID (position__c)
2.) Reference (position__r)
3.) Related List (job_applications__r)
How many member variables exist on the child object to reference the parent object?

1.) Foreign key ( record.relationship_field__c = '001234567891ABC'; )
2.) Object reference ( record.relationship_field__r = new ParentObject__c (); )
How many member variables exist on the parent object to reference the child object?
What does SOQL stand for?
Salesforce Object Query Language
Where can you execute a SOQL query?
1.) the queryString parameter in the query() call
2.) Apex statements
3.) Visualforce controllers and getter methods
4.) Schema explorer in the IDE
5.) Query Editor in the Developer Console
What are the three main components (or clauses) of a SOQL statement?
2.) FROM
What are the two ways to insert SOQL within Apex?
1.) Square-bracket expressions
2.) Database.query() method
What approach must you use to implement a dynamic SOQL query at runtime in Apex?
Database.query() method
How many possible data types can a SOQL query return?
What are the possible data types that a SOQL query can return?
1.) List of sObjects
2.) A single sObject
3.) An integer
What is the format of a SOQL query that returns an integer?
SELECT count() FROM Account WHERE FieldName[__c] = 'some_value'
What does the AVG() function do within a SOQL query?
AVG() returns the average value of a numeric field
What does the COUNT() function do within a SOQL query?
COUNT() returns the total number of rows matching the query criteria
What does the COUNT_DISTINCT() function do within a SOQL query
COUNT_DISTINCT() returns the number of distinct non-null field values
What does the MIN() function do within a SOQL query?
MIN() returns the minimum value of a field
What does the MAX() function do within a SOQL query?
MAX() returns the maximum value of a field
What does the SUM() function do within a SOQL query?
SUM() returns the total sum of a numeric field
What does the CALENDAR_MONTH() function do within a SOQL query?
CALENDAR_MONTH() returns a number representing the calendar month of a date field
What does the DAY_IN_MONTH() function do within a SOQL query?
DAN_IN_MONTH() returns a number representing the day in the month of a date field
What does the FISCAL_YEAR() function do within a SOQL query?
FISCAL_YEAR() returns a number representing the fiscal year of a date field
What does the WEEK_IN_YEAR() function do within a SOQL query?
WEEK_IN_YEAR() returns a number representing the week in the year for a date field
What is SOQL binding?
SOQL binding is the act of referencing a variable or expression within a square-bracketed SOQL query.
What is the syntax for binding a variable or expression to a SOQL query in Apex?
Use a colon. For example...

[SELECT Id FROM Account WHERE Type = :myTypeValue]

[SELECT Id FROM Account WHERE Type = :('Active' + 'Client')]
True or False: SOQL only returns data for fields that are specified in the SELECT clause of the query
True WITH ONE EXCEPTION: The Id field value is implicitly included for records returned in a SOQL query, even if the Id field is not specified in the SELECT clause.
What happens if you try to access a field for a record returned by a SOQL query that was not specified in the SELECT clause?
A system.objectException will be thrown.
What are the two types of iteration variables supported by SOQL FOR() loops?
1.) A single variable. Here, one record will be processed at a time.
2.) A list of variables. Here, records will be processed in blocks of 200.
SOQL "IN" keyword
Used for bulk queries. Uses a Set or List of sObjects as an argument.

... WHERE Id IN :accountIdSet
SOQL "LIKE" keyword
Allows you to select records using wildcards.

... WHERE Name LIKE 'Senior%'
SOQL "GROUP BY" keyword
Provides summary data about selected groups.


List<AggregateResult> agr = [SELECT Zip_Code__c, COUNT(Name) FROM Account GROUP BY Zip_Code__c];
True or False: SOQL queries including aggregate functions do not support queryMore().
True. A LIMIT should be applied to these queries to ensure that an exception is not thrown by exceeding the limit of 2,000 rows for queries containing aggregate functions.
Locks the returned records from being updated by another request. The records can only be updated within the current trigger context, and the locks are released when the transaction ends.
SOQL "ALL ROWS" keyword
Returns both active and deleted records.
What is the purpose of SOQL joins?
SOQL joins allow you to query data from two or more sObjects in a single query based on the relationships between them.
Describe a SOQL Right Outer Join
A SOQL Right Outer Join is when you pull in Parent data via a SOQL query on a Child object. For example:
SELECT Id, Account.Name, Account.Industry from Contacts
Describe a SOQL Left Outer Join
A SOQL Left Outer Join is when you pull in related child data via a SOQL query on a Parent object. For example:
SELECT Id, Name, (SELECT First Name, Last Name FROM Contacts) FROM Accounts
Describe a Semi-Join SOQL Query
Used to query for Parent records that have at least one Child object. For example:

SELECT Id, Name FROM Position__c where Id IN (SELECT Position__c FROM Job_Application__c)
Describe a Right Inner Join SOQL Query
Used to query for Child records that have a Parent record. For example:

SELECT Id, Position__r.Name FROM Job_Application__c WHERE Position__c != NULL
Describe a Right Anti-Join SOQL Query
Used to query for Child objects that do NOT have a Parent record. For example:

SELECT Id FROM Job_Application__c WHERE Position__c = null
Describe a Left Anti-Join SOQL Query
Used to retrieve Parent objects that do not have any Child records. For example:

SELECT Id, Name FROM Position__c WHERE Id NOT IN (SELECT Position__c from Job_Application__c)
Describe a Right Inner Join Without Remote Condition SOQL Query
Used to query for Child records that have Parent records that meet certain criteria (i.e. certain Parent records only). For example:
SELECT Id, Position__r.Name FROM Job_Application__c WHERE Position__r.Type = 'Technology'
What is a Multi-Level Relationship?
When you chain relationships together to access Grandparent records, and beyond. For example:

What are the limits of Multi-Level Relationships? There are two.
1.) You can only reference a maximum of 5 child-to-parent relationships in a single query.
2.) You can only have one parent-to-child relationship in a single query.
In the Developer Console, where can you run a SOQL query?
In the Query Editor
In the Developer Console, is there a feature that allows you to view the details of an object, such as the fields that exist?
Yes. Choose File > Open Resource and select an object file (ex. Job_Application__c). The result is a tab that lists the available fields for the object. Great for running SOQL queries on the fly without having to dig for information manually through the native Setup menu, etc.
True or False: In the Query Editor of the Developer Console, after opening an object resource, you can click to select fields from the resource, and then click "Add Fields" to automatically build a default SOQL query that includes those fields.
False. After opening an object resource, you can click to select fields from the resource, and then click "Query" to automatically build a default SOQL query that includes those fields.
In the Schema Builder, is a feature provided to allow you to clear the default layout?
Yes. Click "Clear All" to remove all objects and relationships from the workspace area.
True or False: In the Schema Builder, after adding objects to the workspace area, you must manually rearrange the objects if you would like the layout to better fit the viewing area.
False. Click "Auto Layout" to have the Schema Builder auto-arrange the layout to best fit the viewing area.
In the Schema Builder, can you toggle between viewing Labels and API Names for Objects and Fields?
Yes. Under View Options, select "Display Element Labels" or "Display Element Names"
What does SOSL stand for?
Salesforce Object Search Language
What are some differences between SOSL and SOQL?
1.) SOSL can search multiple objects at once.
2.) SOSL is used to perform text searches.
What is the return type of a SOSL query?
A list of lists of sObjects.
By default, SOSL excludes: (three answers)
1.) Dates
2.) IDs
3.) Numbers
By default, SOSL returns only the [BLANK] of found records.
What is an example of a SOSL query?
[ FIND 'Acme' RETURNING Account(Name), Opportunity(Name) ]
A SOSL statement specifies: (4 items)
1.) A text expression (i.e. what to search for)
2.) The scope of fields to search
3.) The list of objects and fields to retrieve
4.) The conditions for selecting rows in the source objects
You use the FIND clause of a SOSL query to:
Specify the search string, surrounded by single quotes.

Ex. FIND 'Acme'
True or False: The FIND clause does not support wildcard searches.
Describe the wildcards available in the FIND clause for SOSL queries.
1.) An asterisk (*) is a wildcard for one or more characters in the middle or the end of a search string.

2.) A question mark (?) is a wildcard for one character in the middle or the end of a search string.
You use the IN clause of a SOSL query to:
Limit the type of fields to search.
Name 5 options for the search scope of the IN clause.
True or False: The IN clause is optional.
If the IN clause is not specified, what is the default search scope of a SOSL query?
You use the RETURNING clause of a SOSL query to:
Limit the results to the specified object types, as well as the fields to return for each of the specified objects.
True or False: The RETURNING clause is optional.
Trick question! It is optional via the API, but required via Apex code.
If you do not specify any objects or fields in the RETURNING clause...
The search will return the IDs for matching records across all searchable objects.
You use the WHERE clause of a SOSL query to:
Filter search results by specific field values.
True or False: The WHERE clause of a SOSL query is optional.
What difference exists when executing a SOSL query in the Query Editor of the Developer Console?
The search term must be enclosed in curly braces {} instead of single quotes ''.
Can you bind variables to a SOSL query like you can with a SOQL query? If so, is the format the same?
Yes, and Yes.
When should you use SOQL instead of SOSL? (three reasons)
1.) When the sObject type is predetermined.
2.) When the result data needs to be joined.
3.) When you want to query beyond text, email, or phone fields.
When should you use SOSL instead of SOQL?
When you need to search across multiple sObject types.
What does DML stand for?
Data Manipulation Language
What are the 6 DML actions that you can execute?
1.) insert
2.) update
3.) upsert
4.) delete
5.) merge
6.) undelete
What are the two forms of DML operations?
1.) Standalone statements (insert myAccount;)
2.) Database methods (Database.insert(myAccount);)
Why would a developer use a Database method instead of a standalone statement?
When you need to control additional features, such as:

1.) truncation behavior
2.) locale options
3.) triggering assignment rules
True or False: When using Database methods, you can perform a DML operation on multiple sObjects at a time.
False. Like standalone statements, Database methods can execute on a single record or a list of records, but are limited to one sObject type at a time.
When a DML standalone statement is executed against a list of records, if one record encounters an error, what happens?
All of the records will fail. None of the records will be inserted/updated/etc.
When a DML Database method is executed against a list of records, if one record encounters an error, what happens?
It depends on the setting of the allOrNone parameter. If allOrNone is set to false, then Apex handles errors on a case by case basis. Even if an error is encountered with one record in the list, the operation will continue with the other records in the list.
When using a Database method to execute a DML operation, and if allOrNone is set to false, how can you check the results of the operation?
Database insert and update methods return a SaveResult object that can be used to get the results of the operation.
True or False: You must specify a value for the allOrNone parameter when using a Database method.
What is the default value of the allOrNone parameter of a Database method?
What is the return type for the Database.insert method?
What is the return type for the Database.update method?
What is the return type for the Database.update method when a LIST of records is updated?
What is the return type for the Database.delete method?
What is the return type for the Database.merge method?
What is the return type for the Database.upsert method?
What is the return type for the Database.undelete method?
What are the three methods of a SaveResult object?
1.) ID getId()
2.) List<Database.Error> getErrors()
3.) Boolean isSuccess()
What additional options does the Database.DMLOptions object allow you to control?
1.) Truncation behavior
2.) Trigger assignment rules
3.) Locale options
4.) Trigger email notifications based on specific events such as:
- Creation of a new Case, Case Comment, or Task
- Conversion of a Case email to a Contact
- New User email notification
- Password reset
Assume "c" represents an existing Contact, and "a" represents an existing Account. Are these statements valid?

c.Account = a;
c.Account.Name = 'Salesforce';
c.LastName = 'Smith';
update c;
update c.Account;
What is the governor limit for DML statements in a single context?
When should you include DML operations within a FOR() loop?
What is the most efficient way to process bulk DML operations?
Iterate over lists of sObjects using a SOQL FOR() loop and process DML operations over chunks at a time. This helps to avoid heap limits. For example.

for(List<Position__c> myList: [SELECT Id FROM Position__c])
for(Position__c p: myList)
//some logic here...
What if I exceed the total number of allowed SOQL queries?
Move SOQL queries outside of loops.
What if I exceed the number of DML operations?
Process DML operations in bulk.
What if I exceed the total number of records retrieved by SOQL queries?
Create selective queries that filter indexed fields, such as primary keys, foreign keys, names, audit dates, or external Id fields.
If you still believe you will exceed governor limits on DML operations even after using best practices for your code, what other option may exist?
Use Apex asynchronous batch processing for DML operations.
Define a Database Transaction.
A transaction is a sequence of events based on the first event you perform.
A transaction is controlled by:
The trigger, the web service, or the anonymous block that executed the apex script.
What happens to database changes if the Apex script contains an uncaught exception?
All changes are rolled back.
What are Transaction Savepoints?
Transation Savepoints are steps in the transaction that specify the state of the database at a specific time.
What are Transaction Savepoints used for?
1.) Control the transaction level
2.) Define logic for rolling back a section or subset of the DML operation
Do Transaction Savepoints (the setSavepoint() and rollBack() methods) count against the limit of DML statements?
What are triggers?
Triggers are the primary mechanism to execute code within Apex. Triggers execute code whenever a DML event occurs on a specific sObject.
What are the two types of triggers?
Before and After triggers
What can before triggers do?
They can update or validate values before they are saved to the database.
What can an after trigger do?
They can access field values that are set automatically or affect changes in other records.
Do triggers fire regardless of how the triggering data has been saved? i.e. via the UI, API, Data Loader, etc.
What should you consider if you want custom logic to fire only via the UI?
Consider using a Visualforce Page and Apex Controller.
What is the format for declaring a trigger?
trigger [trigger name] on [object name] (trigger events) {//trigger body}
What are the seven different trigger events?
1.) before insert
2.) after insert
3.) before update
4.) after update
5.) before delete
6.) after delete
7.) after undelete
Where can you create a trigger?
1.) IDE
2.) Developer Console
3.) UI - Setup > Build > Develop > Apex Triggers
4.) UI - Setup > Customize > Standard Object > Triggers
5.) UI - Setup > Create > Custom Object > Triggers
What is the Execution Order of Triggers?
1.) Original record loaded, or new record initialized for insert
2.) New record field values are loaded and override old values
3.) System validation rules
4.) BEFORE triggers
5.) Custom validation rules. Most system validation rules run again.
6.) Record saved, but not committed
7.) AFTER triggers
8.) Assignment rules,
9.) Auto-response rules
10.) Workflow rules
11.) Workflow field updates will update the record again
12.) BEFORE and AFTER triggers executed again IF field are updated based on Workflow rules (up to 13 times)
13.) Processes
14.) Escalation rules
15.) Roll-up summary fields or cross-object formula fields are updated in the parent records, and affected records are saved.
16.) REPEAT the same process for affected grand parent records.
17.) Criteria-based sharing is evaluated
18.) All DML operations are committed to the database
19.) Post-commit logic (such as sending emails) is executed.
What is the runtime context of a trigger called?
Trigger context
What is the trigger context?
The trigger context is the data available to the trigger
Name examples of Trigger Context Boolean Variables
What is trigger.size?
Trigger.size returns the total number of new and old sObjects.
What is returns a list of the new versions of sObjects.
When is available?
In INSERT and UPDATE triggers.
When can be modified?
In BEFORE triggers
What is trigger.newMap?
Returns a map of IDs to sObjects for the new records
When is trigger.newMap available?
What is trigger.old?
Contains a list of the original records
When is trigger.old available?
UPDATE and DELETE triggers
True or False: trigger.old is Read Only.
What is the value of trigger.old in the context of an INSERT trigger?
What is trigger.oldMap?
Returns a map of IDs to sObjects for the original versions of the records.
How can you prevent a DML event from being completed for, or taking action on, a record?
Use the addError() method.
What can you use trigger.newMap and trigger.oldMap for?
To correlate records with query results. For example, use the keySet() of one of these maps to query for related records and then take some action, such as preventing Opportunities from being deleted if they have one more related Quotes.
addError() can be applied to... (2 answers)
1.) An sObject
2.) A specific field
How do you apply the addError() method to an sObject?
Opportunity myOpp;
//some code...
myOpp.addError('You cannot do that!');
How do you apply the addError() method to a specific field on an sObject?
Opportunity myOpp;
//some code...
myOpp.myFieldName__c.addError('Do not touch this field!');
True or False: All triggers run in User context by default.
False. Triggers run in System mode by default.
Can a Trigger be made to run in User context?
Yes, using the WITH SHARING keywords.
What keywords can Trigger code contain?
Only those applicable to an inner class
Can Trigger code contain the STATIC keyword?
True or False: Cascading execution of Triggers (i.e. firing another trigger as a result of DML within the current trigger) are part of the same execution context with respect to Governor Limits.
True or False: Upsert events cause Insert and Update triggers to fire.
What do Merge events cause to fire?
1.) DELETE triggers for the unsuccessful records.
2.) UPDATE triggers for the successful records.
What is a limitation of UNDELETE triggers?
Undelete triggers only work with top-level objects, although related records are also undeleted.
What is a limitation of an AFTER UNDELETE trigger?
They only work with recovered records.
True or False: Field History is not recorded until the end of a trigger event.
What is Apex Sharing?
Apex Sharing is a way to create custom sharing reasons and control access levels for those custom reasons using Apex scripts.
True or False: Custom Apex Sharing Reasons are available for Custom Objects and Top-Level Standard Objects.
False. Custom Apex Sharing Reasons are only available for Custom Objects.
What is the Name format of an object's sharing table in Apex?
What is the format to set the Row Cause for a custom object sharing record?
Object_Share myShare = new Object__Share();
myShare.RowCause = Schema.Object_Share.RowCause.Custom_Sharing_Reason__c
What can be used to recalculate Apex managed sharing?
A batch job.
What is the recommended approach for recalculating Apex managed sharing on a record?
1.) Delete all sharing for the record for the RowCause
2.) Calculate and add all sharing for the record for the RowCause
True or False: You can change the sObject that a Trigger is associated with after the Trigger is created.
How many records can a trigger process at a time?
What happens if the number of records in the DML operation exceeds the number of records that a trigger can process at one time?
The trigger will process records in chunks of 200.
True or False: The BEFORE trigger can be used to access system-updated field values and affect changes in other records.
False. The AFTER trigger is needed for this.
How many times will a trigger execute for 1,001 records?
6 times.
What are Exceptions?
Exceptions are errors and other events that disrupt the execution of code.
What four keywords allow you to handle Exceptions in Apex?
1.) throw
2.) try
3.) catch
4.) finally
What does the throw keyword do?
throw indicates that an error has occurred, and provides an Exception object.
What does the try keyword do?
try indicates the block of code where the Exception may occur.
What does the catch keyword do?
catch identifies the block of code that can handle a specific Exception.
What does the finally keyword do?
finally represents a block of code that is guaranteed to fire after a try block.
What are some system-defined exceptions?
1.) DmlException
2.) ListException
3.) MathException
4.) SecurityException
5.) NullPointerException
6.) QueryException
7.) SObjectException
8.) StringException
9.) TypeException
True or False: Developers can create their own custom Exception classes.
True. These are called User-Defined Exception Classes.
When are User-Defined Exception Classes most handy?
When Developers need more control over the type of behavior performed by a program when handling Exceptions.
What two requirements must User-Defined Exception Classes follow?
1.) They must end with the string "Exception".
2.) They must extend the system-defined Exception class.
True or False: User-Defined Exception Classes can indirectly extend the system-defined Exception class.

public virtual class BaseException extends Exception {}
public class OtherException extends BaseException {}
What does the getCause() method do?
Returns the cause of the exception as an Exception.
What does the getMessage() method do?
Returns the error message that is displayed to the end user
What does the getTypeName() method do?
Returns the type of exception that has occurred.
What does the initCause(sObject Exception) method do?
Sets the cause for the Exception, if not already set.
What is Debugging?
Debugging is the process of locating and reducing the number of defects or errors within our code.
What two utilities are used for debugging?
1.) Logs
2.) Anonymous Blocks
Where can Logs be generated?
1.) Debug Logs in the Setup menu
2.) Developer Console
3.) IDE
What is the size limit for a System Log?
2 MB
Each organization can retain up to [REDACTED] MB of Logs.
50 MB
What do Log Filters do?
Log Filters determine the type of information returned in a Log.
How many Log Filters exist?
What are the different Log Filters that exist?
1.) Database
2.) Workflow
3.) Validation
4.) Callout
5.) Apex Code
6.) Apex Profiling
7.) Visualforce
8.) System
What does the Database filter include?
1.) System.debug() log messages
2.) DML statements
3.) Inline SOQL or SOSL queries
What does the Apex Profiling filter include?
Cumulative profiling information, such as SOQL queries that use the most resources, the number of Apex method calls, and the total time that each method called needed for processing.
What does the System filter include?
Information regarding calls to all System methods.
What are System Log Levels used for?
System Log Levels are used to control the amount of information returned in a Log.
What do the ERROR, WARN, and INFO Levels include?
Error, warning, and information messages.
What does the DEBUG Level include?
Lower level messages and messages generated by the System.debug() method.
What do the FINE and FINER Levels include?
1.) System.debug() messages
2.) DML Statements
3.) SOQL and SOSL inline statements
4.) Entrance and Exit of every user-defined method
What does the FINEST Level include?
1.) Everything included in the FINE and FINER Levels
2.) Changes in the sharing context
3.) Variable declaration statements
4.) Start of loops
5.) All loop controls
6.) Thrown exceptions
7.) Static and class initialization code
True or False: Debug Log Levels apply to the entire Log, and cannot be granularly controlled at the class or trigger level.
True or False: Unless otherwise overridden, the Log Levels of a class called from another class will inherit the Level of the class that called it.
True or False: Debug Logs capture different information than System Logs.
Can anonymous blocks include the STATIC keyword?
True or False: You can specify the User for which the anonymous block should be executed as.
False. Anonymous blocks are always executed using the full permissions of the current user.
Do anonymous blocks run in system mode?
What are the three ways that anonymous blocks can be executed?
1.) executeAnonymous() web services API call
2.) Developer Console
3.) IDE
What are Apex Unit Test Methods?
Methods that verify whether or not the code is working is expected.
What are two facts about Apex Unit Test Methods?
1.) They do not take any arguments.
2.) They do not commit any data to the database, even if DML operations are executed within the method.
How do you annotate a Test Class?
public class myTestClass {}
What are the two ways that you can annotate a Test Method?
1.) The annotation @isTest
2.) The keyword testMethod
True or False: Governor limits are not applied to test methods.
What can be used to properly test governor limits for your code?
startTest() and stopTest()
Do you have to use startTest() and stopTest() together?
Where in the test method should you place the startTest() method?
After all of the test infrastructure has been set and just before the call to the actual methods to be tested.
Can unit tests be run via a call to the API?
Yes, using the runTests() method.
What do the compileClasses() and compileTriggers() methods do?
They can be used to just compile the code without tests being run in order to verify that the syntax and references of the code are correct.
What percentage of Apex code must be covered by unit tests?
What methods can be used to verify the results of a unit test?
What method can be used to test record sharing and data accessibility?
What are some best practices for creating Apex unit tests?
1.) Create 200 test records to test that your code is properly "bulkified".
2.) Test your code using valid and invalid inputs.
3.) Do not assume that your record Ids are in sequential order
4.) Use the ORDER BY keyword to ensure that records are returned in the expected order
How should you annotate a method that is used to setup a test by creating test data, etc.?
What are the two types of Logs?
System Logs and Debug Logs.
What is the pattern typically followed for Deployment?
1.) Develop
2.) Integrate
3.) Stage
4.) Training and Production
What does the Develop step include?
1.) Development in a developer sandbox
2.) Unit testing
3.) Integration testing
What does the Integrate step include?
Solution modules are tested as a group. All or most of the individual components are combined to form a complete solution, and are tested in another sandbox.
What does the Stage step include?
1.) Full regression testing
2.) Load testing
3.) UAT
4.) Specific new feature testing
What does the Production/Training step include?
The change control board approves changes for deployment to Production and/or Training following successful completion of testing.
Can you directly create Apex code in Production?
Where is Apex code unit tested?
In a sandbox before deployment, and in Production after deployment.
How can you deploy org-specific data in metadata?
Switch to work-offline mode, remove the org-specific information from the metadata, and deploy that to Production.
What are four ways that metadata can be deployed to an environment?
1.) IDE
2.) Migration Tool
3.) Change Sets
4.) Third party tools (likely at cost)
How can you create your own SOAP Web Service method?
Use the webservice keyword
Can you have a private Web Service method?
No. Web Service methods are inherently global
True or False: The webservice keyword can be considered as an access modifier that enables the same level of access as the global keyword.
False. The webservice keyword can be considered as an access modifier that enables MORE access than the global keyword.
From where can custom SOAP Web Service methods be invoked?
1.) AJAX Toolkit
2.) Custom client program (i.e. Java application, etc.)
How do you call a Web Service from the AJAX Toolkit?
1.) Import the apex.js library
2.) Use the execute() method and pass in the name of the class and method
How do you call a Web Service from a client program?
Generate the class WSDL and include it in the client program, at which point the client program can call the web service directly.