Process Automation and Logic Flashcards

1
Q

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 performing a .size() or .length() method call?

A. do { … } while (condition)

B. while (condition) {…}

C. for (init_stmt; exit_condition; increment_stmt) { … }

D. for (variable : list_or_set) { … }

A

D. for (variable : list_or_set) { … }

List or set iteration for loops do not need the size of the collection to run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the value of x after the code segment executes?

String x = 'A'; 
Integer i = 10; 
if ( i < 15 ){  
   i = 15;  
   x = 'B'; 
}  elseif ( i < 20 ){ 
   x = 'C'; 
}  else {  
   x = 'D'; 
} 

A. ‘A’

B. ‘B’

C. ‘C’

D. ‘D’

A

B. ‘B’

These if statements are evaluating the value of i. Since i is equal to 10 then i is less than 15 and i will be reassigned the value 15 and x will be equal to ‘B’. Once the values are assigned the if statement is no longer run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which three are accurate statements about variable scope? (Select three answers.)

A. A variable can be defined at any point in a block.

B. Sub-blocks cannot reuse a parent block’s variable name.

C. Sub-blocks can reuse a parent block’s variable name if its value is null.

D. Parallel blocks can use the same variable name.

E. A static variable can restrict the scope to the current block if its value is null.

A

A. A variable can be defined at any point in a block.

B. Sub-blocks cannot reuse a parent block’s variable name.

D. Parallel blocks can use the same variable name.

A variable is valid from the point where it is declared inside of the code.

Variables can be defined anywhere within a block. However Sub-blocks can’t redefine a variable name that has already been used within a parent block.

The same name can be used inside parallel blocks because the scope of the variable is limited only to the particular block that it was defined in.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which two users can edit a record after it has been locked for approval?

A

An administrator and a user who is assigned as the current approver

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens to changes in the result when a Visualforce page calls an Apex controller, which calls another Apex class, and then hits a governor limit?

A

Any changes up to the error are rolled back.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A developer in a Salesforce org with 100 accounts executes the following code using the Developer Console:

Account myAccount = new Account(Name='MyAccount');  insert myAccount;    
for (Integer x = 0; x < 150; x++){   
   Account newAccount = new 
      Account(Name='MyAccount' + x);   
   try{    	
      insert newAccount;   	
   } catch (Exception ex){ 	 
      System.Debug(ex);    	 
      x = 'D';   
   }  
}   
insert new Account(Name='MyAccount');  

How many accounts are in the org after this code is run?

A. 100

B. 101

C. 102

D. 252

A

A. 100

Salesforce has a governor limit of 150 DML statements per transaction. The Salesforce org originally starts with 100 accounts. The first DML statement inserts the first account leaving 149 DML statements available. Inside the for loop it tries to make 150 DML statements. But the limit is reached when x = 149. When this happens the transaction aborts and all data changes are rolled back. The only thing that is left is the original 100 accounts. Since the error happened the last insert statement is never reached. Best practice is to avoid DML statements inside for loops.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which two statements should a developer avoid using inside procedural loops? (Select two answers.)

A. List contacts = [select id, salutation, firstname, lastname, email from Contact where accountId = :a.Id];

B. update contactList;

C. if (o.accountid == a.id)

D. System.debug(‘Amount of CPU time (in ms) used so far: ‘ + Limits.getCpuTime());

A

A. List contacts = [select id, salutation, firstname, lastname, email from Contact where accountId = :a.Id];

B. update contactList;

Avoid using SOQL in loops since there is a governor limit that enforces a maximum number of SOQL queries. When these operations are placed inside a loop, database operations are invoked once per iteration of the loop making it very easy to reach these governor limits. Best practice is to query once to obtain all results, and then iterate over the results.

Avoid using DML in loops since there is a governor limit that enforces a maximum number of DML statements. When these operations are placed inside a loop, database operations are invoked once per iteration of the loop making it very easy to reach these governor limits.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which data structure is returned to a developer when performing a SOSL search?

A

A list of lists of sObjects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A developer runs the following anonymous code block:

List acc = [SELECT Id FROM Account LIMIT 10];
Delete acc;
Database.emptyRecycleBin(acc); system.debug(Limits.getDMLStatements()+’,’ +Limits.getLimitDMLStatements());

What is the result?

A

2,150

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A developer has the following query:

Contact c = [SELECT id, firstname, lastname, email FROM Contact WHERE lastname = ‘Smith’];

What does the query return if there is no contact with the last name Smith?

A

An error that no rows are found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

A developer writes a Salesforce Object Query Language (SOQL) query to find child records for a specific parent. How many levels can be returned in a single query?

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an accurate constructor for a custom controller named MyController?

A.
public MyController(List objects){
accounts = (List)objects;
}

B.
public MyController(){   
   account = new Account();   
}  

C.
public MyController(SObject obj){
account = (Account) obj;
}

D.
public MyController(List objects){
accounts = (List)objects;
}

A
B.
public MyController(){   
   account = new Account();   
} 

To create a constructor for a custom controller, the constructor cannot have a parameter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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. The code fails when the developer uses the Apex Data Loader to insert 10,000 lead records. The developer has the following code block:

01 for(Lead l : Trigger.new){  
02  if(l.PostalCode != null){  
03   List terrList = [SELECT Id FROM Territory\_\_c Where PostalCode\_\_c = :l.PostalCode];  
04   if(terrList.size() > 0){  
05    l.Territory\_\_c = terrList[0].Id;  
06   }  
07  }  
08 }  

Which line of code causes the code block to fail?

A. 01: Trigger.new is not valid in a before insert trigger.

B. 02: A NullPointer exception is thrown if PostalCode is null.

C. 03: A SOQL query is located inside of the for loop code.

D. 05: The lead in a before insert trigger cannot be updated.

A

C. 03: A SOQL query is located inside of the for loop code.

This will fail on the record number 201 because the limit of SOQL queries is 200. Best practice is to avoid SOQL queries inside for loops.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A developer needs to automatically populate the ReportsTo field in a contact record based on the values of the related Account and Department fields in the contact record. Which two trigger types should the developer create? (Select two answers.)

A. before update

B. before insert

C. after insert

D. after update

A

A. before update

B. before insert

The developer should use a before update/insert trigger. That way there is no need for an extra DML statement. It is good practice to use before triggers to validate updated/inserted records before they are saved.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

A hierarchy custom setting stores a specific URL for each profile in Salesforce. Which statement can a developer use to retrieve the correct URL for the current user’s profile and display this on a Visualforce Page?

A. {!$Setup.Url_Settings__c.URL__c}

B. {!$Setup.Url_Settings__c.Instance[Profile.Id].URL__c}

C. {!$Setup.Url_Settings__c[Profile.Id].URL__c}

D. {!$Setup.Url_Settings__c[$Profile.Id].URL__c}

A

A. {!$Setup.Url_Settings__c.URL__c}

A specific profile should get a specific record type. So, simply getting a record type Id will not work. We need to know what each profile should get. Hierarchy custom settings support unique values per profile.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In which order does Salesforce execute events upon saving a record?

A. Validation Rules; Before Triggers; Validation Rules; After Triggers; Assignment Rules; Workflow Rules; Commit

B. Before Triggers; Validation Rules; After Triggers; Workflow Rules; Assignment Rules; Commit

C. Validation Rules; Before Triggers; After Triggers; Workflow Rules; Assignment Rules; Commit

D. Before Triggers; Validation Rules; Assignment Rules; Workflow Rules; After Triggers; Commit

A

A. Validation Rules; Before Triggers; Validation Rules; After Triggers; Assignment Rules; Workflow Rules; Commit

  • Runs system validation check.
  • Executes all before triggers.
  • Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules. The only system validation that Salesforce doesn’t run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.
  • Executes duplicate rules. If the duplicate rule identifies the record as a duplicate and uses the block action, the record is not saved and no further steps, such as after triggers and workflow rules, are taken.
  • Saves the record to the database, but doesn’t commit yet.
  • Executes all after triggers.
  • Executes assignment rules.
  • Executes auto-response rules.
  • Executes workflow rules.
  • If there are workflow field updates, updates the record again.
  • If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again.
17
Q

How can a developer determine if a CustomObject__c record has been manually shared with the current user in Apex?

A. By calling the profile settings of the current user

B. By querying CustomObject__Share

C. By calling the isShared() method for the record

D. By querying the role hierarchy

A

B. By querying CustomObject__Share

To access sharing programmatically, you must use the share object associated with the standard or custom object for which you want to share. All custom object sharing objects are named MyCustomObject__Share, where MyCustomObject is the name of the custom object.

18
Q

A developer creates a workflow rule declaratively that 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?

A. The Apex trigger is fired more than once.

B. The workflow rule is fired more than once.

C. No changes are made to the data.

D. Both the Apex trigger and workflow rule are fired only once.

A

A. The Apex trigger is fired more than once.

After the workflow rule, the trigger is executed again.

19
Q

A developer wants to display all of the available record types for a Case object. The developer also wants to display the picklist values for the Case.Status field. The Case object and the Case.Status field are on a custom Visualforce page. Which two actions should the developer perform to get the record types and picklist values in the controller? (Select two answers.)

A. Use Schema.RecordTypeInfo returned by Case.SObjectType.getDescribe().getRecordTypeInfos().

B. Use SOQL to query case records in the org to get all the RecordType values available for Case.

C. Use Schema.PicklistEntry returned by Case.Status.getDescribe().getPicklistValues().

D. Use SOQL to query case records in the org to get all values for the Status picklist field.

A

A. Use Schema.RecordTypeInfo returned by Case.SObjectType.getDescribe().getRecordTypeInfos().

C. Use Schema.PicklistEntry returned by Case.Status.getDescribe().getPicklistValues().

A RecordTypeInfo object is returned from the sObject describe result using the getRecordTypeInfos method.

getPicklistValues() returns a list of PicklistEntry objects.

20
Q

A developer writes a before insert trigger. Which context variable can the developer use to access the incoming records in the trigger body?

A

The Trigger.new context variable

21
Q

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?

A

The isCreatable() method

22
Q

In the execution order of triggers, what three steps happen after the before triggers execute, and before the after triggers execute?

A
  1. The Before triggers are executed
  2. System validation steps are run again and user-defined 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.
23
Q

True or False: Workflows support publishing platform events.

A

False

24
Q

A developer needs to create records for the object Property__c. The developer creates the following code block:

01 List propertiesToCreate = helperClass.createProperties();  
02 try {  
03   
04 } catch (Exception exp){  
05 //Exception handling  
06 }  

Which line of code should the developer insert at line 03 to ensure that at least some records are created, even if a few records have errors and fail to be created?

A. insert propertiesToCreate;

B. Database.insert(propertiesToCreate,false);

C. Database.insert(propertiesToCreate,System.ALLOW_PARTIAL);

D. Database.insert(propertiesToCreate);

A

B. Database.insert(propertiesToCreate,false);

This stems from the method Database.insert(recordToInsert, allOrNone) where ‘allOrNone’ is a Boolean value. If the Boolean value is set to false and a record fails, the remainder of the DML operation will succeed. If it’s set to true an exception is thrown if the method is not completely successful.

25
Q

Name the type that the Boolean will inherit from: Boolean b = true;

A

Object

26
Q

SOQL statement results can evaluate to the following data types except?

A. A list of sObjects

B. A String

C. A single sObject

D. An Integer

A

B. A String

27
Q

What is true about how Salesforce deals with cross-site scripting (XSS) attacks? Choose 2 answers.

A. All standard Visualforce components, which start with < apex >, have anti-XSS filters in place

B. Custom JavaScript is protected from XSS.

C. Salesforce has implemented filters that screen out harmful characters in most output methods as one of the anti-XSS defenses.

D. Escape should be enabled for Visualforce Tags e.g. < apex:outputText escape=”true” value=”{!$CurrentPage.parameters.userInput}” / >

A

A. All standard Visualforce components, which start with < apex >, have anti-XSS filters in place

C. Salesforce has implemented filters that screen out harmful characters in most output methods as one of the anti-XSS defenses.

28
Q

How can a developer check the maximum number of digits for an integer field?

A. Use the getScale() method of the DescribeFieldResult Class

B. Use the getSize() method of the DescribeFieldResult Class

C. Use the getDigits() method of the DescribeFieldResult Class

D. Use the getLength() method of the DescribeFieldResult Class

A

C. Use the getDigits() method of the DescribeFieldResult Class

29
Q

What is true regarding accessing sharing programmatically? Choose 3 answers.

A. AccountShare is the sharing object for the Account object

B. Account__Share is the sharing object for the Account object

C. CustomObject__Share is the sharing object for a custom object

D. Objects on the detail side of a master-detail relationship have do not have a sharing object

A

A. AccountShare is the sharing object for the Account object

C. CustomObject__Share is the sharing object for a custom object

D. Objects on the detail side of a master-detail relationship have do not have a sharing object

30
Q

How can SOQL injection be prevented?

A. Use the escapeSingleQuotes method

B. Use the preventInjection method

C. Use the preventQuotes method

D. Use the preventDatabaseCommands method

A

A. Use the escapeSingleQuotes method

31
Q

Exceptions show errors and other events that disrupt the normal flow of code execution. Which of the following statements are true about Apex Exception Handling? Choose 3 answers.

A. The try statement identifies a block of code in which an exception could occur.

B. The catch statement identifies a block of code that handles a particular type of exception.

C. The finally statement is required and gets executed after the catch block executes.

D. You can have multiple Catch blocks to catch all different kinds of exceptions. If you use a generic exception catcher, it must be the first Catch block.

E. Comparatively, a throw statement allows you to signal that an error has occurred., while try, catch, and finally can be used to pull through from an exception.

A

A. The try statement identifies a block of code in which an exception could occur.

B. The catch statement identifies a block of code that handles a particular type of exception.

E. Comparatively, a throw statement allows you to signal that an error has occurred., while try, catch, and finally can be used to pull through from an exception.

32
Q

What will be the result of the following code if there are 2 accounts named ABC? try { Account myAccount = [SELECT id, name FROM Account WHERE name = ‘ABC’]; } catch (Exception e) { System.debug(‘Exception caught’); } System.debug(‘Continuing’); string myString = ‘Salesforce’; System.debug(‘String size is ‘ + myString.length());

A. No exceptions will be thrown and the code will execute normally

B. An exception will be thrown and the code will stop immediately

C. An exception will be caught and the code will stop after executing the code in the catch block

D. An exception will be caught and the code will continue after executing the code in the catch block

A

D. An exception will be caught and the code will continue after executing the code in the catch block

33
Q

How can a developer check if the current user is able to view a particular field?

A. Use the isViewable() method of the DescribeField Class

B. Use the isViewable() method of the DescribeFieldResult Class

C. Use the isAccessible() method of the DescribeField Class

D. Use the isAccessible() method of the DescribeFieldResult Class

A

D. Use the isAccessible() method of the DescribeFieldResult Class

34
Q

Which of the following are true regarding custom setting data? Choose 2 answers.

A. Custom setting data can be accessed by formula fields, validation rules, Apex and Visualforce pages

B. Custom setting data cannot be queried using SOQL

C. Custom setting data needs to be queried once using SOQL and then it is stored in the cache

D. There are two types of custom setting data, hiearchy and list

A

A. Custom setting data can be accessed by formula fields, validation rules, Apex and Visualforce pages

D. There are two types of custom setting data, hiearchy and list

35
Q

Which of the following are true regarding developing in the Salesforce multitenant environment? Choose 2 answers.

A. Salesforce delivers polyglot persistence transparently

B. It is not possible to index application data as each tenant stores different types of data in the same application table

C. Queries need to be selective in terms of the number of records returned

D. The custom domain feature ensures that different customers do not access each others data

A

A. Salesforce delivers polyglot persistence transparently

C. Queries need to be selective in terms of the number of records returned

36
Q

For which of the following requirements, could a formula field not be used?

A. A custom field needs to have a default value such as the week from the current date

B. Display a traffic light image of red, yellow or green based on case priority

C. Concatenate values from long text area fields

D. Create a link to an application outside of Salesforce, passing parameters including the session id

A

C. Concatenate values from long text area fields

37
Q

Apex and Visualforce pages are prone to Data Access Control issues, to avoid this, a developer should:

A. Use the [with sharing] keyword in Apex classes

B. Use the [without sharing] keyword in Apex classes

C. Use the [shareable] keyword in Apex classes

D. Use the [non shareable] keyword in Apex classes

A

A. Use the [with sharing] keyword in Apex classes

38
Q

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

A. Data import

B. Bulk Force.com API calls

C. Lightning Events

D. Mass actions

E. Visualforce Actions

A

A. Data import

B. Bulk Force.com API calls

D. Mass actions

39
Q

Which of the following is required when defining an Apex Class Method?

A. Access Modifiers

B. Return Data type

C. Definition Modifiers

D. Input parameters

A

B. Return Data type