Cert Prep: PD1: Automation and Logic

Review Declarative Features and Basic Constructs in Apex

Identify declarative process automation features. Identify and use basic constructs within Apex.
  • When the number of records in a recordset is unknown, which control statement should a developer use to implement a set of code that executes for every record in the recordset, without perorming a .size() or .length() method call? for(variable : list_or_set) {...}
  • What is the value of x after the code segment below executes? B
String x = 'A';
Integer i = 10;
if (i < 15 ) {
    i = 15;
    x = 'B';
} elseif ( i < 20 ) {
    x = 'C';
} else {
    x = 'D';
  • Which three are accurate statements about variable scope? A variable can be defined at any point in a block. Sub-blocks cannot reuse a parent block’s variable name. Parallel blocks can use the same variable name.
  • An sObject named Application__c has a lookup relationship to another sObject named Position__c. Both Application__c and Position__c have a picklist field named Status__c. When the Status__c field on Position__c is updated, the Status__c field on Application__c needs to be populated automatically with the same value. How? By using a trigger with a DML operation

  • Which two users can edit a record after it has been locked for approval? An administrator and a user who is assigned as the current approver
  • What happens to changes in the result when a page calls an Apex controller, which calls another Apex class, and then hits a governor limit? Any changes up to the error are rolled back

Get a Refresh on SOQL, SOSL, and DML

Write SOSL, SOQL and DML statements in Apex. Identify the implications of governor limits on Apex transactions. Implement exception handling in Apex, including custom exceptions as needed.
  • A developer in a Salesforce org with 100 accounts executes the code to the right using the Developer Console. How many accounts are in the org after the code below executes? 100. Salesforce has a governor limit of 150 DML statements per transaction.When the code tries to insert more than 150 all inserts are rolled back.
  • Which two statements should a developer avoid using inside procedural loops? List<Contact> contacts = [select id, salutation, firstname, lastname, email from Contact where accountId = :a.Id]; and update contactList;
Account myAccount = new Account(Name='MyAccount');
insert myAccount;

for (Integer x = 0; x< 150; x++) {
    Account newAccount = new Account(Name='MyAccount' + i);
    try {
        insert newAccount;
    } catch (Exception ex) {
insert new Account(Name='MyAccount');
  • A developer needs to create records for the object Property__c. The developer creates this code block. Which line of code should the developer insert at line 3 to ensure that at least some records are created, even if a few records have errors and fail to be created? Database.inserrt(propertiesToCreate,false);
List<Property__c> propertiesToCreate = helperClass.createProperties();
try {
    // insert here
} catch (Exception exp) {
    // Exception handling
  • Which data struccture is returned to a developer when performing a SOSL search? **List<List<sObject>>
  • A developer runs the anonymous code block below. What is displayed after this code executes? 2, 150
List<Account> acc = [SELECT Id from Account LIMIT 10];
  • A developer has the query below. What does the query return if there is no contact with the last name Smith? Contact c = [SELECT id, firstname, laastname, email FROM Contact WHERE lastname = 'Smith']; A System.QueryException that no rows are found
  • A developer writes a SOQL query to find child records for a specific parent. How many levels can be returned in a single query? 1
  • What are three data types or collection of data types that SOQL statements populate or evaluate? An integer, a single sObject, or a list of sObjects

Study Up on Apex Classes and Triggers

Write Apex classes and triggers while following best practices. Describe the relationship between Apex transactions, the save order of execution, and the potential for recursion and cascading.
  • What is an accurate constructor for a custom controller named MyController? public MyController(){ account = new Account(); }
  • A developer uses a before insert trigger on the Lead object to fetch the Territory__c object, where the Territory__c.PostalCode__c matches the Lead.PostalCode__c. The code fails when the developer uses the Apex Data Loader to insert 10,000 lead records. The developer uses the code block below. What line of code causes the code block to fail? A SOQL query is located inside of the FOR loop code
for (lead l : Trigger.new) {
    if (l.PostalCode != null) {
        List<Territory__c> terrList = [SELECT Id FROM Territory__c WHERE PostalCode__c = :l.PostalCode];
        if(terrList.size() > 0){
            l.Territory__c = terrList[0].Id;
  • A developer needs to automatically populate the ReportsTo field in a contact record based on the values of the related Account and Department fields on the contact record. Which two trigger types should the developer create? before update & before insert. This way there is no need for an extra DML statement. It is good practice to use before triggers to validate updated records before they are saved.
  • According to the order of execution, in which sequence does Salesforce execute these high-level events upon saving a record? Validation Rules; Before Triggers; Before Save Flows; Workflow Rules; After Triggers; Flow Automations; Workflow Rules; After Save Flows; Commit
    Note that Before Save Flows are executed prior to Before Triggers, and Validation Rules are executed multiple times
  • How can a developer determine if a CustomObject__c record has been manually shared with the current user in Apex? By querying CustomObject__Share
  • A workflow rule changes the value of a field on an object. An Apex After Update trigger exists for the object. What happens when a user updates a record? The Apex trigger is fired more than once. After the workflow rule, the trigger is executed again.

  • A developer writes a before insert trigger. Which context variable can the developer use to access the incoming records in the trigger body? Trigger.New context variable
  • Which method can a developer use to determine, from the DescribeSObjectResult, if the current user will be able to create records for an object in Apex? isCreatable() method
  • In the execution order of triggers, what three steps happen after the before triggers execute, and before the after triggers execute? 1. The Before triggers are executed. 2. System validation steps are run again and user-defined custom validation rules are checked. 3. Executes duplicate rules. 4. The record is saved to the database but doesn’t commit yet. 5. Executes all After triggers.
  • Do After save flows run prior to after triggers? No, after triggers run first