PD1: Logic and Process Automation Part 2 (46%)

What are valid use cases for using a custom controller in a Visualforce page?
Choose 2 answers.

A. A Visualforce page needs to add new actions to a standard controller.
B. A Visualforce page should override the save action of the standard controller.
C. A Visualforce page needs to run in system mode.
D. A Visualforce page should replace the functionality of the standard controller.

Answers: C and D

Which of the following code snippets are acceptable to be included within a looping statement?
Choose 2 answers.

A. if(acc.NumberOfEmployees > 5000){
B. insert accountList;
C. System.debug(‘The following account has been updated’ + ‘acc.Id ‘);
D. Opportunity getOpp = [SELECT Id, AccountId FROM Opportunity WHERE AccountId =: acc.Id];

Answers: A and C

A developer needs to implement apex code in a multi-tenant platform. Choose the appropriate pattern to follow.
Choose 1 answer.

A. To prevent access from other server tenants, the “with sharing” keyword is used in Apex classes.
B. To minimize deployment errors, Apex code is developed in a different environment.
C. To avoid data concurrency issues, DML operations should only be used on one record at a time.
D. To prevent exceeding governor limits, select the fewest fields and filter records in SOQL statements.

Answer: D

On what event should the trigger below be fired?

Trigger createCallingCard on Contact (EVENT) {
List<CallingCard__c> cardList = new List<CallingCard__c>();
for (Contact con : Trigger.new) {
CallingCard__c newCard = new CallingCard__c();
newCard.Name = con.Name;
newCard.Phone = con.Phone;
newCard.Address = con.Address;
newCard.relatedContact__c = con.Id;
cardList.add(newCard);
}
insert cardList;
}

Choose 1 answer.

A. After Update
B. Before Delete
C. Before Insert
D. After Insert

Answer: D

String is one of the primitive data types in Salesforce. Given the following options, what is a valid value that a string data type variable can contain?
Choose 1 answer.

A. ‘Salesforce’
B. 3.14159
C. TRUE
D. “Salesforce”

Answer: A

A developer imported 4,000 account records into Salesforce and wishes to verify if these were created correctly. There are already over 60,000 accounts already existing in the system. The developer implemented Apex code to check the records created. What is the correct pattern to follow?
Choose 1 answer.

A. SOQL statements should be placed inside loops when matching to ensure updated results for every iteration.
B. DML should be used on one instance/record at a time
C. Use the [with sharing] keyword to ensure the query will find the appropriate records.
D. Add criteria to SOQL Select statements to filter out unnecessary records.

Answer: D

A Salesforce Developer has created a method inside a custom controller with the following code to return an error message on the Visualforce page that uses the controller. However, during testing, it was found that the Visualforce page does not return the error. What could be the possible reason?

Controller code:

ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,’Unable to Sort LastName’);
ApexPages.addMessage(myMsg);

Visualforce code:

<apex:page controller = “ContactsListController”>
<apex:form>
<apex:pageBlock title = “Contacts List” id = “contacts_list”>

<!– Contacts List –>
<apex:pageBlockTable value = “{!contacts}” var=”ct”>
<apex:column value=”{ct.FirstName}”>
<apex:facet name = “header”>
<apex:commandLink action=”{! sortByFirstName}”
reRender=”contacts_list”>First Name
</apex:commandLink>
</apex:facet>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Choose 1 answer.

A. The whole page is refreshing and at that point loses the message.
B. The entity that causes the error is on the reRender attribute which will cause the error to not show.
C. The message component <apex:pageMessages> is not added to the page.
D. Incorrect syntax for ApexPages on the controller side.

Answer: C

What trigger context variable will return true if the current context for the Apex code is a trigger, not a Visualforce page, a Web service, or an executeanonymous() API call?
Choose 1 answer.

A. oldMap
B. isUpdate
C. isUndelete
D. isExecuting

Answer: D

A developer is considering using a standard controller on a Visualforce page. Which of the following are valid considerations about standard controllers?
Choose 3 answers.

A. To associate a standard controller with a Visualforce page, use the standardController attribute on the <apex:page> tag and assign it the name of any Salesforce object that can be queried using the Force.com API.
B. The standard controller provides a set of standard actions, such as create, edit, save, and delete, that you can add to your pages using standard user interface elements such as buttons and links.
C. Every standard controller includes a getter method that returns the record specified by the id query string parameter in the page URL.
D. A Standard controller can retrieve a list of items to be displayed, make a callout to an external web service, validate and insert data
E. To associate a standard controller with a Visualforce page, use the ‘controller’ attribute on the <apex:page> tag and assign it the name of any Salesforce object that can be queried using the Force.com API.

Answers: A, B and C

A junior developer frequently experiences governor limit errors when running Apex Triggers. As a senior developer, which of the following are best practices that you could advise?
Choose 2 answers.

A. Use an Apex handler class for multiple triggers.
B. Use lists to perform DML operations on multiple records.
C. Use SOQL queries only within FOR loops.
D. Use a combination of collections (e.g. maps, lists) and streamlined queries.

Answers: B and D

When writing an Apex Trigger, what should a developer keep in mind?
Choose 2 answers.

A. An Apex Trigger should be logic-less and delegate the logic responsibilities to a handler class.
B. A single Apex Trigger is all you need for each object.
C. An Apex Trigger should use @future annotation in performing DML operations.
D. An Apex Trigger should not cause another trigger to be fired

Answers: A and B

What standard controller action aborts an edit operation and returns the user to the page where the edit originated?
Choose 1 answer.

A. Cancel
B. Revoke
C. Break
D. Stop

Answer: A

A developer created a trigger with the following code below:

trigger lineItemPerInvoice on Invoice_Statement__c (before insert, before update) {
for(Invoice_Statement__c inv : trigger.new) {
List<LineItem__c> liList = [SELECT Id, Units_Sold__c FROM LineItem__c WHERE Invoice_Statement__c IN: inv];
for(LineItem__c li : liList) {
//do logic here
}
}
}

What is true about the code snippet?
Choose 3 answers.

A. The trigger shows an example of inefficient querying of child items.
B. The trigger bypasses the problem of having the SOQL query called for each item.
C. When updating more than 100 Invoice statement records, it will throw a run time exception for exceeding the governor limit for SOQL queries.
D. The trigger has only one SOQL query performed and is still within the governor limits
E. The SOQL query performed inside the loop retrieves the Line item for each invoice statement.

Answers: A, C and E

What will be the result of running the following code?

for (Integer x = 0; x < 200; x++) {
Account newAccount = new Account ( Name= ‘MyAccount-‘ + x);
try {
insert newAccount;
System.debug(Limits.getDMLStatements());
}
catch(exception ex) {
System.Debug(‘Caught Exception’);
System.Debug(ex);
}
}

insert new Account(Name=’MyAccount-last’);

Choose 1 answer.

A. 150 accounts will be inserted
B. A limit exception will be caught and one account will be inserted
C. 201 accounts will be inserted
D. No accounts will be inserted

Answer: D

When a developer designs SOQL relationship queries, there are several boundaries to consider. Which of the following statements are true?
Choose 2 answers.

A. Up to five levels of parent-to-child relationship can be specified in a query.
B. For a child-to-parent relationship, only one level can be specified in a query.
C. A relationship between objects to create a join in SOQL is a prerequisite.
D. Each SOQL query can have up to four joins across external objects and other types of objects.

Answers: C and D

Given the following options, what data type should the developer use to store queried records via SOQL?
Choose 1 answer.

A. List
B. Group
C. Enum
D. Container

Answer: A

What does Trigger.new contain?
Choose 1 answer.

A. A map of sObject ids and records that are new or modified and available in insert and update triggers
B. A set of new versions of records available in insert and update triggers
C. A list of new versions of records and is available in insert, update and undelete triggers
D. A list of new records and is available only in insert triggers

Answer: C

Which of the following statements is true about defining getter methods?
Choose 1 answer.

A. Getter methods are suggested to include logic that increments a variable, write a log message, or add a new record to the database.
B. Every value that is calculated by a controller and displayed in a page must have a corresponding getter method
C. Use the name of the getter method in an expression to display the results of a getter method in a page.
D. The [get] method is used to pass data from Visualforce page to Apex controller.

Answer: B

A developer is required to access Opportunity records on a Visualforce page without using a custom controller. How can the developer satisfy this requirement?
Choose 1 answer.

A. <apex:page controller=”Opportunity” recordListVar=”opportunities”>
B. <apex:page standardController=”Opportunity” getAllRecordsVar=”opportunities”>
C. <apex:page controller=”Opportunity” recordSetVar=”opportunities”>
D. <apex:page standardController=”Opportunity” recordSetVar=”opportunities”>

Answer: D

A developer implemented two workflow field updates. Field update on Rule A triggers Rule B and the other way around. What will happen?
Choose 1 answer.

A. The workflow reevaluation will automatically be suspended.
B. A field update exception will occur and will be displayed for the current user.
C. It will cause a loop and the organization will exceed its limit for workflow time triggers per hour.
D. This will not happen as field updates implicitly prohibit recursion.

Answer: C

A developer is required to override the standard Opportunity view button using a Visualforce page. What should the developer do?
Choose 1 answer.

A. Use a custom controller and replicate the opportunity detail page
B. Use a controller extension
C. Use the Opportunity StandardController
D. Use the StandardListController

Answer: C

Which of the following is a standard controller action that aborts an edit operation?
Choose 1 answer.

A. Save
B. Cancel
C. Close
D. Delete

Answer: B

What are valid use cases for using a controller extension in a Visualforce page?
Choose 2 answers.

A. You need to override the edit action of the standard controller
B. Functionality of the standard controller should be replaced
C. You want to select if the page runs in system mode
D. A new action needs to be added

Answers: A and D

A developer has created the following trigger to update the description of existing Contract records:

List<Contract> getContracts = new List<Contract>();

for(Opportunity opp: (List<Opportunity>) Trigger.New) {
Contract con = [SELECT Id FROM Contract WHERE Id =: opp.ContractId];
con.Description = ‘This is the contract for Opportunity’ + opp.Name;
getContracts.add(con);
}

update getContracts;

How many Contract records will be updated when a developer loads 2000 Opportunity records?

Choose 1 answer.

A. 0
B. 1
C. 100
D. 2000

Answer: A

What is the correct syntax for writing an Apex Trigger?
Choose 1 answer.

A. trigger ObjectName on trigger_events (TriggerName) { code_block; }
B. trigger ObjectName on TriggerName (trigger_events) { code_block; }
C. trigger TriggerName on TriggerEvents (ObjectName) { code_block; }
D. trigger TriggerName on ObjectName (trigger_events) { code_block; }

Answer: D

What is true in the code below?

try {
String sampleStr;
if (sampleStr.contains(‘abcd’)) {
system.debug(‘Hello World’);
}
}
catch(DmlException e) {
System.debug(‘DmlException: ‘ + e.getMessage());
}
catch(SObjectException e) {
System.debug(‘SObjectException: ‘ + e.getMessage());
}
catch(ListException e) {
System.debug(‘ListException: ‘ + e.getMessage());
}
catch(Exception e) {
System.debug(‘Exception: ‘ + e.getMessage());
}

Choose 1 answer.

A. Line 3 will cause a NullPointerException and the last catch block (Line 12), as a generic Exception, will handle it.
B. No catch blocks (LIne 6,8,10) match the exception criteria, therefore the error is still unhandled.
C. All catch blocks (Line 6,8,10) will be executed even if only one matches the exception criteria.
D. The try-block will be successfully executed with no errors.

Answer: A

A developer needs to get all IDs of related Accounts on all of the Contact records. What collection data type should the developer use to avoid having duplicate IDs?
Choose 1 answer.

A. Map
B. Set
C. List
D. Group

Answer: B

A developer has the following requirement:

Every time a record on Contact with isPrimaryContact field set to true is deleted, update the field hasPrimaryContact to false of its related Account.

The developer should create a trigger in what event?

Choose 1 answer.

A. After Update
B. After Delete
C. Before Delete
D. Before Update

Answer: B

A developer has written the following code to do a SOSL search: FIND {New York}. What will be returned?
Choose 1 answer.

A. A map of sObjects that match the search term
B. A map of Accounts or Contacts that match the search term
C. A list of Contacts that match the search term
D. A list of lists of sObjects and their records that match the search term

Answer: D

A custom object has a workflow rule that updates a field when a certain set of criteria is met. A ‘before update’ Apex trigger has also been defined on the object. What will happen when a user updates a record so that it meets the criteria of the workflow rule?
Choose 1 answer.

A. The Apex trigger will be fired first, voiding the Workflow Rule due to the order of execution
B. Both will be fired only once
C. The Apex trigger will be fired twice
D. An exception will be thrown due to a conflict between the two

Answer: C

Which of the following actions can be performed in the Before Update trigger?
Choose 2 answers.

A. Change its own field values using trigger.new.
B. Modifying trigger.old values.
C. Delete trigger.new values to avoid changes.
D. Create a validation before accepting own field changes.

Answers: A and D

A developer needs to write a trigger on the [Survey] custom object. This trigger will use the email address on the [Survey] record as a unique key to look for a matching email address on the existing contact records. If a matching email address is found, then the [Survey] record [Name of Contact] field should be populated with the name of the contact found. What is the best collection data type to use when storing contact records?
Choose 1 answer.

A. List
B. Set
C. Map
D. Group

Answer: C

When a trigger fires, it can process multiple records so all triggers should be written to accommodate bulk transactions. Which of the following are typical examples of bulk transactions?
Choose 3 answers.

A. Mass actions
B. Lightning Events
C. Visualforce Actions
D. Data import
E. Bulk Force.com API calls

Answers: A, D and E

What is true about Custom Exceptions?
Choose 3 answers.

A. They are not capable of re-throwing a caught exception.
B. They are primarily useful if the method is called by another method and the exception handling is transferred to the other method.
C. They are built by extending the built-in Exception class and should end with the word Exception.
D. They are capable of specifying detailed error messages and have additional custom error handling in catch blocks.
E. Built-in and custom Apex exceptions behave the same in throwing and catching exceptions.

Answers: B, C and D

A developer is required to create a trigger that every time the Type field on Request object is updated, the Owner field should be changed as well, either to a User or Queue. What trigger event should the developer use?
Choose 1 answer.

A. Before Delete
B. After Update
C. Before Update
D. After Merge

Answer: C

What method displays a custom error message on a particular record and prevents any DML operations thereafter?
Choose 1 answer.

A. add(errMsg)
B. clear(errMsg)
C. throwError(errMsg)
D. addError(errMsg)

Answer: D

As per the order of execution, when will an email created from a workflow email alert be sent?
Choose 1 answer.

A. After all DML operations are committed to the database.
B. When all before triggers are executed.
C. Before entitlement rules execution.
D. After workflow rule execution.

Answer: A

A developer needs to create a trigger that will throw an error whenever the user tries to delete a contact that is not associated to an account. What trigger event should the developer use?
Choose 1 answer.

A. After Delete
B. Before Delete
C. After Insert
D. Before Insert

Answer: B

What is the order of execution when a record is saved?
Choose 1 answer.

A. System Validation Rules, Workflow Rules, All Validation Rules, Before Triggers, After Triggers, Assignment Rules, Commit
B. System Validation Rules, User Defined Validation Rules, Before Triggers, Workflow Rules, After Triggers, Workflow Rules, Assignment Rules, Commit
C. System Validation Rules, Before Triggers, All Validation Rules, Duplicate Rules, After Triggers, Assignment Rules, Workflow Rules, Commit
D. System Validation Rules, Before Triggers, All Validation Rules, Workflow Rules, After Triggers, Assignment Rules, Commit

Answer: C

Which of the following statements related to Apex best practices about avoiding SOQL queries inside For Loops are true?
Choose 3 answers.

A. Running a SOQL query inside a for loop is advised as long as the LIMIT command is properly used.
B. If a developer needs to query, query once, retrieve all the necessary data in a single query, then iterate over the results.
C. The following code is an example of improper SOQL limit utilization: for (Account a : [SELECT Id,Name From Account Limit 1000]) { //code_block }
D. When queries are placed inside a for loop, a query is executed on each iteration and governor limit is easily exceeded.
E. By moving queries outside of for loops, your code will run faster, and is less likely to exceed governor limits.

Answers: B, D and E

What attribute should a developer use to associate a page with the standard controller for a custom object?
Choose 1 answer.

A. customController
B. controller
C. standardController
D. visualController

Answer: C

Which of the following statements are true about Apex generic exceptions and built-in exceptions?
Choose 3 answers.

A. The generic Exception catches all exception types except LimitException
B. NullPointerException occurs when there is a problem with unauthorized access, such as trying to access an sObject when the current user does not have access to it.
C. QueryException occurs when there is a problem with SOQL queries.
D. NoAccessException occurs when there is a problem with unauthorized access such as trying to access an sObject that the current user does not have access to.
E. The LimitException can be caught by using a combination of one or more Exception types.

Answers: A, C and D

What will happen when the following code is executed?

trigger CaseTrigger on Case (after insert) {
List<Case> casesToInsert = new List<Case>();
for (Case parent: Trigger.new) {
Case child = new Case();
child.ParentId = parent.Id;
child.Subject = parent.Subject + ‘ Child’;
casesToInsert.add(child);
}
insert casesToInsert;
}

Choose 1 answer.

A. Child cases will be inserted for each Parent case.
B. The trigger will throw an exception because it is not bulkified.
C. No child cases will be created.
D. The trigger will be recursively called which will result in an infinite loop and will eventually throw an exception.

Answer: D

The following code snippet fails during bulk data load:

for(Contact con : Trigger.new) {
if(con.PostalCode != null) {
List<State__c> stateList = [SELECT Id, Postal__c From State__c WHERE Postal__c =: con.PostalCode];
if (stateList.size()>0) {
con.State__c = stateList[0].Id;
}
}
}

What is the root cause?
Choose 1 answer.

A. Variable ‘con’ is not declared.
B. No update DML over list of Contacts
C. Condition is invalid and will always be null.
D. SOQL query is located inside the for loop code.

Answer: D

What will happen if a governor limit is hit from an Apex class that was called from an Apex controller class of a VisualForce page?
Choose 2 answers.

A. It will save all changes made from the Apex class.
B. It will rollback all changes made up to the error.
C. An exception will be thrown.
D. It will save all changes made from the Apex controller class.

Answers: B and C

If a developer is required to create a page that will show and add actions on a set of records, what controller can accomplish this with the least effort?
Choose 1 answer.

A. Lightning Bundle Controller
B. Standard Controller
C. Standard List Controller
D. Custom Controller

Answer: C

Which of the following are valid Apex data types?
Choose 3 answers.

A. Text
B. Currency
C. Blob
D. ID
E. Enum

Answers: C, D and E

What trigger context variable will return a map of IDs to the old versions of the sObject records?
Choose 1 answer.

A. updateMap
B. insertMap
C. oldMap
D. newMap

Answer: C

A developer is trying to create a trigger that will set the record type of an Invoice record, prior to insertion, based on the value of the Industry picklist that is selected. What trigger event should the developer use?
Choose 1 answer.

A. After Insert
B. Before Insert
C. After Update
D. Before Delete

Answer: B

A developer can develop code to insert records that will allow successful inserts and will record errors for unsuccessful records. This is called partial processing. However, this method will not throw an exception. How should a developer handle the possible exceptions?
Choose 1 answer.

A. Use Database.EachResult Class
B. Use Database.SaveResult Class
C. Use Database.SuccessResult Class
D. Use Database.ErrorResult Class

Answer: B

Given the following Visualforce page snippet, which of the following statements are true?

<apex:page standardController=”Lead” extensions=”LeadExtA, LeadExtB, LeadExtC “>
<apex:outputText value=”{!display}” />
</apex:page>

Choose 3 answers.
A. LeadExtA, LeadExtB or LeadExtC cannot exist by itself without the ‘Lead’ standard controller.
B. It is possible to have multiple extensions, and extensions can be reused on different controllers.
C. If a method is declared across all extensions, LeadExtC will override all methods.
D. The controller extensions are LeadExtA, LeadExtB, LeadExtC.
E. The <apex:outputText> component will not render any value since {$ } notation is not used.

Answers: A, B and D

Which of the following action methods are supported by standard controllers?
Choose 3 answers.

A. Quicksave
B. Delete
C. Select
D. Cancel
E. Export

Answers: A, B and D

What is true regarding a future method?
Choose 2 answers.

A. A method annotated with @future can call another method that also has the @future annotation.
B. Methods that are annotated with @future identify methods that are executed synchronously.
C. Methods that are annotated with @future identify methods that are executed asynchronously.
D. Methods annotated with @future can only return a void type.

Answers: C and D

Which of the following ways can be used to throw a custom exception?
Choose 3 answers.

A. throw new customExceptionName();
B. throw new customExceptionName().addError(‘Error Message Here’);
C. throw new customExceptionName(‘Error Message Here’);
D. throw new customExceptionName(e);
E. throw new customExceptionName().setMessage(‘Error Message Here’);

Answers: A, C and D

Which of the following statements about triggers are true?
Choose 3 answers.

A. Trigger code is stored as metadata under the object which they are associated with.
B. For the Attachment, ContentDocument and Note standard objects, a trigger cannot be created in the Salesforce user interface.
C. A developer can specify the version of Apex and API which can be used with the Trigger.
D. Apex Triggers are always active and cannot be turned off.
E. Triggers can be used to detect a before undelete event.

Answers: A, B and C

What exception method should the developer use to know the error message that displays for the user?
Choose 1 answer.

A. getStackTraceString()
B. getTypeName()
C. getMessage()
D. getCause()

Answer: C

Which of the following is the correct syntax for a try-catch-finally block?
Choose 1 answer.

A. finally{ *code here* } catch (Exception e) { *code here* } try { *code here* }
B. catch { *code here* } finally (Exception e) { *code here* } try { *code here* }
C. catch { *code here* } try (Exception e) { *code here* } finally { *code here* }
D. try{ *code here* } catch (Exception e) { *code here* } finally { *code here* }

Answer: D

When catching exceptions, the default notification actions in uncaught exceptions will be lost, so developers are expected to formulate their own. Which of the following ways can a developer notify the user of the issue?
Choose 2 answers.

A. Sending an email that may add to the catch-block of a try-catch construct
B. Adding a @future method to create a record on a custom object that could catch the error details.
C. Using .addError method on errors that may occur in DML on Apex Triggers.
D. Using ApexPages.message class to create an error message for display on a Visualforce page.

Answers: C and D

Which of the following statements are true about controller extensions?
Choose 3 answers.

A. If an extension works in conjunction with a standard controller, the standard controller methods will also be available.
B. The extension is associated with the page using the ‘extensions’ attribute of the <apex:page> component.
C. Only one controller extension can be defined for a single page.
D. A standard or custom controller is an extension of the controller extension.
E. A controller extension is an Apex class that extends the functionality of a standard or custom controller.

Answers: A, B and E

Which of the following statements about setter methods are true?
Choose 3 answers.

A. The [set] method is used to pass values from Visualforce page to the controller.
B. Setter methods are executed prior to action methods.
C. Setter methods must always be named setVariable.
D. The [set] method is used to pass values from the controller to a Visualforce page.
E. It is necessary to include a setter method to pass values into a controller.

Answers: A, B and C

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.