Process Automation and Logic Flashcards
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) { … }
D. for (variable : list_or_set) { … }
List or set iteration for loops do not need the size of the collection to run.
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’
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.
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 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.
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 Visualforce 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.
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. 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.
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. 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.
Which data structure is returned to a developer when performing a SOSL search?
A list of lists of sObjects
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?
2,150
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?
An error that no rows are found.
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?
1
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;
}
B. public MyController(){ account = new Account(); }
To create a constructor for a custom controller, the constructor cannot have a parameter.
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.
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.
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. 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.
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. {!$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.
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. 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.
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
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.
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. The Apex trigger is fired more than once.
After the workflow rule, the trigger is executed again.
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. 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.
A developer writes a before insert trigger. Which context variable can the developer use to access the incoming records in the trigger body?
The 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?
The isCreatable() method
In the execution order of triggers, what three steps happen after the before triggers execute, and before the after triggers execute?
- The Before triggers are executed
- System validation steps are run again and user-defined validation rules are checked.
- Executes duplicate rules.
- The record is saved to the database but doesn’t commit yet.
- Executes all after triggers.
True or False: Workflows support publishing platform events.
False
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);
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.