DF Process Automation an Logic P2 Flashcards

1
Q

Cosmic Support is building a complex record-triggered flow to automate its onboarding process. While saving the flow, issues seem to be encountered preventing the flow from being saved. Which feature can be used to help troubleshoot the flow?

A. Debug button
B. Custom Error element
C. Flow Trigger Explore
D. Errors and Warnings Pane

A

✅ D. Errors and Warnings Pane

The Errors and Warnings pane in Flow Builder provides a summarized list of issues that prevent a flow from being saved or activated. Clicking on the error or warning highlights or opens up the configuration window of the element that is causing the issue.

The Flow Trigger Explorer is used to view related record-triggered flows and their status, order, and trigger types (before-save, after-save, anonymous, and scheduled). The Debug button is used to run the flow in the debug mode. The Custom Error element in Flow Builder is used to deliberately terminate the flow transaction when a required condition, for example, is not met.

Troubleshoot Configuration Issues Systematically with the Errors and Warning Pane

Explanation:
The Errors and Warnings Pane in Flow Builder displays any errors or warnings that prevent the flow from being saved. It provides detailed information about what needs to be fixed, such as missing required fields, invalid configurations, or unsupported logic.

Why not the others?
A. Debug button

The Debug button is used to test and debug a flow after it has been saved. It does not help troubleshoot issues that prevent the flow from being saved.

B. Custom Error element

The Custom Error element is used to handle and display custom error messages during flow execution. It is not used for troubleshooting flow configuration issues.

C. Flow Trigger Explorer

Flow Trigger Explorer is a tool used to view and manage record-triggered flows in an org. It does not provide troubleshooting capabilities for saving flows.

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

Which Apex trigger context variable returns a map of IDs to the old versions of the sObject records?

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

A

A. oldMap

The Trigger.oldMap context variable returns a map collection where the key is the record ID and the value is the old version of the sObject record. This trigger context variable is only available in update and delete triggers.

The Trigger.newMap context variable returns a map collection where the key is the record ID and the value is the new version of the sObject record. An ‘updateMap’ or ‘insertMap’ trigger context variable does not exist.

Trigger Context Variables

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

Considering Apex best practices, which of the following example code snippets is acceptable to be included within a for loop?

A. insert accountRecord;
B. Database.update(accountRecords, false);
C. Opportunity opp = [SELECT Name FROM Opportunity WHERE AccountId = :accountRecord.Id LIMIT 1];
D. if (accountRecord.NumberOfEmployees > 1000) { accountRecord.Priority__c = ‘High’; }

A

D. if (accountRecord.NumberOfEmployees > 1000) { accountRecord.Priority__c = ‘High’; }

A common mistake is that queries or DML statements are placed inside a for loop. There are governor limits that restrict the allowed number of SOQL queries and DML statements (insert, update, delete, undelete) that can be performed in a single transaction. When these statements are placed inside a for loop, the operation will be invoked once per iteration, making it very easy to exceed the governor limits.

Improve Your Apex Code

The 15 Apex Commandments

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

There are two existing workflow field updates, and their ‘Re-evaluate Workflow Rules after Field Change’ options have been enabled. The field update on workflow rule A triggers workflow rule B, and vice-versa. What will be the result of the field updates in this scenario?

A. Recursion does not happen as workflow field updates automatically prevent such occurrence.
B. A recursive loop may happen and exceed the org limit for workflow time triggers per hour.
C. Only the first triggered workflow will run and the second workflow will be prevented from running.
D. The workflow re-evaluation will be automatically prevented from running to avoid a recursion.

A

B. A recursive loop may happen and exceed the org limit for workflow time triggers per hour.

Workflow rules can create recursive loops. For example, if a field update for Rule1 triggers Rule2, and a field update for Rule2 triggers Rule1, it will cause recursion and may cause the organization to exceed its limit for workflow time triggers per hour.

Workflow field updates do not have a recursion prevention mechanism. Both workflows will be triggered as one causes the other to run. The workflow re-evaluation will be executed.

Field Updates That Reevaluate Workflow Rules

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

A developer needs to store the IDs of all the related accounts from a list of contacts. Which collection data types can be used to prevent duplicate IDs?

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

A

B. Set and Map

A set is an unordered collection of elements that do not allow duplicate values. To add an element to a set, the add() method of the Set class is used. This method will add an element only if the element doesn’t exist yet in the collection.

A map, which is an ordered collection of key-value pairs, can also be used since it does not allow duplicate keys. To add an element to a map, the put() method is used. In this case, the key will contain the ID of the record while the value can contain the record itself, for example, or any other value.

A list collection allows storing duplicate values. An ‘Enum’ is an abstract data type used for storing a predefined set of finite values and is not a valid collection data type. A ‘Group’ data type does not exist.

Sets

Maps

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

A real estate company uses a custom checkbox field called ‘Is Primary Contact’ on the Contact object to allow users to easily mark a contact record as the primary contact of an account. When the primary contact is deleted, the value of a custom checkbox field called ‘Has Primary Contact’ on the related account should be set to false automatically. While creating an Apex trigger on the Contact object, which trigger event should be used to meet this requirement?

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

A

D. After Delete

Since the requirement is to update the related account after the primary contact has been deleted, the ‘After Delete’ trigger event on the Contact object should be used.

The ‘Before Delete’ trigger event is not recommended as it must be ensured that the contact has been successfully deleted first before updating the related account. The ‘Before Update’ and ‘After Update’ trigger events are fired when a record is updated.

To update another record (the related Account) when a child record (the Contact) is deleted, the recommended pattern is to use an After Delete trigger on the Contact. This is because in an after context, the record has already been removed from the database, and you can safely update a different object (the parent Account in this case).

Therefore, the correct answer is:

D. After Delete.

Why “After Delete” Is Best
Before Delete is primarily used for logic on the record being deleted itself (for example, to prevent deletion by throwing an error). While you could technically update a parent record in a before trigger, Salesforce best practices recommend using after triggers when modifying other objects, as the parent’s data can be cleanly updated after the child record’s final state is determined.
After Delete allows you to access the old record values in Trigger.old or Trigger.oldMap, making it straightforward to identify the parent and then update the parent record (e.g., setting Has_Primary_Contact__c = false).
Hence, to set the parent Account’s Has_Primary_Contact__c to false after its primary Contact has been deleted, choose an After Delete trigger.

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

Which of the following statements about triggers is true?

A. A developer can specify the version of Apex and API to be used with the trigger.
B. Apex triggers can be used to detect a ‘before undelete’ event.
C. Apex triggers are always active and cannot be turned off.
D. Attachment, ContentDocument, and Note standard object triggers cannot be created in the Salesforce UI.

A

A. A developer can specify the version of Apex and API to be used with the trigger.
D. Attachment, ContentDocument, and Note standard object triggers cannot be created in the Salesforce UI.

Apex triggers can be activated or deactivated. The ‘Active checkbox’, which is available while editing a trigger, can be used to turn the trigger on or off in a sandbox environment. The deactivated trigger can then be deployed to production to disable the same trigger in production.

In Object Manager, triggers of an object can be found in the Triggers section. The ‘Apex Triggers’ page in Setup can be used to view all triggers of any object. To create Apex triggers for the Attachment, ContentDocument, and Note standard object, the Developer Console, Visual Studio Code, or Code Builder tools can be used.

One may navigate to the version settings to specify the version of Apex and API. Triggers cannot be used to detect a ‘before undelete’ event. Supported trigger events are: before insert, before update, before delete, after insert, after update, after delete, and after undelete.

Defining Triggers

Get Started with Apex Triggers

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

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?

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

A

A. The Apex trigger will be fired twice

According to the order of execution, ‘before’ triggers are run, ‘after’ triggers are run, and then workflow field updates are processed. If a field is updated due to a workflow rule, ‘before update’ and ‘after update’ triggers are run again one more time, and only one more time. In this case, since the record meets the criteria of the workflow rule, the ‘before update’ trigger will be run again after the workflow field update associated with the rule has been processed.

Triggers and Order of Execution

According to Salesforce’s Order of Execution:

The user’s change is saved to the database (after passing system validations).
All before triggers on the object run.
All after triggers on the object run.
Workflow rules are evaluated: if any are true, their field updates happen.
After a workflow field update, the record goes through the save process again, which includes running before and after triggers a second time.
Since you have a before update trigger and also a Workflow Field Update on the same object, here is what happens step by step when a user updates a record:

The before update trigger fires (1st time).
The record is saved (and the after update trigger would fire, if it exists).
The workflow rule is evaluated; the condition is met, so the field is updated.
Because the field was updated by workflow, the record goes back through “before” and “after” triggers again.
So, your before update trigger fires a 2nd time.
Hence, the Apex trigger (before update) will effectively run twice in this scenario.

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

Which of the following statements is true regarding future methods?

A. Methods annotated with @future cannot have a void return type.
B. Methods annotated with @future can call another future method.
C. Methods annotated with @future are executed synchronously.
D. Methods annotared with @future are executed asynchronously.

A

D. Methods annotared with @future are executed asynchronously.

The @future annotation is used to define methods that should be executed asynchronously. Future methods will then be executed only when the org has available resources.

A future method can only return void and does not support other return types. Also, a future method cannot invoke another future method.

Future Annotation

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

A developer has imported 1,000 accounts into Salesforce and wants to verify the records using Apex to ensure that they were created properly. Before the import, there were already 50,000 accounts in the org. Which of the following is a valid consideration related to this use case?

A. Criteria should be added to the SOQL query to filter out unnecessary records.
B. DML statements should be used to process one record at a time only.
C. The ‘with sharing’ keyword should be used to ensure that the query finds the necessary records.
D. A SOQL query should be run inside a loop to retrieve fresh data in each iteration.

A

A. Criteria should be added to the SOQL query to filter out unnecessary records.

The total number of records that can be retrieved by a SOQL query in a single transaction is limited to 50,000. Criteria should be added to the SOQL query in the Apex code to make the query selective and prevent it from exceeding the limit.

If DML statements were used to process one record at a time, the governor limit for the maximum DML statements that can be issued in a transaction would be hit easily. Moreover, a DML statement would not be required for verifying the records.

Running a SOQL query inside a loop would easily hit the governor limit for the maximum queries that can be executed. Using the ‘with sharing’ keyword would limit access to the records by returning only those records that can be accessed by the current user.

Execution Governors and Limits

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