Process Automation and Logic
Process Automation and Logic
● Automation
○ Flow Builder is the primary tool for implementing declarative automation on
the salesforce platform
○ The HTTP callout action in Flow Builder can be used to perform callouts
declaratively
○ POST method, in general, are used to create new records in the external
system using data that is sent along the request.
○ GET methods are used for retrieving data from a server and do not modify
the database.
1
○ HTTP callout action in Flow Builder also supports other methods such as
PATCH and PUT(updating data) as well as DELETE(deleting data)
■ Can be used to specify when the flow is executed in a transaction that
involves over flows.
○ Flow Orchestration and all its referenced flows must be activated before they
can be added as change set components
■ Flow Orchestration and all its associated flows can be added to one
outbound change set
○ Flow Orchestration in itself is a purely declarative solution and do not require
code coverage
■ is a tool used for identifying the record-triggered flows that are
associated with a specific object and trigger type such as ‘created’,
2
‘update’, or ‘deleted’.
■ The tool also allows sorting of the execution order of the flows via
drag-and-drop options and automatically updates the ‘Trigger order’
property value of each record-triggered flow.
■ The tool does not provide data related to flow performance, it cannot
combine flows into a single flow
● Run Flows Without Worrying About User Permissions with System Mode
○ Flows can be configured to run in user or system context depending on how
the flow is launched, or entirely in system context with sharing mode.
○ A slack custom notification type can be created in Notification Builder in
Setup
○ To support sending this type of notification, a Slack app such as the ‘Sales
Cloud for Slack’ app, for example, needs to be installed in Slack and
connected with the Salesforce account of the user. Once the Slack
notification is created, the ‘Send Notification’ core action in Flow Builder can
be used to send the notification when a new opportunity that meets the
criteria is created
3
○ Slack-enabled standard notifications can be cloned and sent using Flow
Builder. Apex is not required to send Slack notifications unless complex logic
is required. Authorizing the Flow Builder action in the Slack workspace is not
a valid configuration step.
■ SOQL does not support the wild card character, or asterisk(*), unlike
SQL
4
● SOQL and SOSL Queries
■ fieldList
5
○ SOSL queries
● The order of search results is based on the order in which the
objects are specified using this clause.
● To access the results from the different sObjects Individually,
an array can be created for each type of sObject
6
●
●
○ SOQL defines several escape sequences to include special characters in
queries.
■ \n, \’, \”, \/ \n, \r, \t, \b, \f, \\
7
■ Like expression only:
○ LIMIT n
■ If a limit is set on the entire query, results are evenly distributed
among the objects returns.
8
■ The following helps you decide when you want to use DML statements
or Database class methods.
9
■ The results list corresponds index-by-index to the original list of
sObject records passed into Database.insert().
○
○ Salesforce does not allow callout to be made after DML operations in the
same transaction
○ A join in SOQL will return results from 2 or more standard/custom objects
10
○ Understanding Relationship Names
■ Dot notation is used to reference fields from parent object (eg: SELECT
Account.Name, Account.BillingState FROM Contact), while a nested
SELECT statement is used to query child records.
■ Standard child relationship names use the plural form of the child
object as the relationship name, so from an Account objects, the
relationship to Contact records is named Contacts.
■ Only custom objects append __r to the end of the child relationship
name. The child relationship name can be found on the lookup field
setup page in the object manager and on the org’s WSDL file.
11
● This example SOQL query includes five levels of
parent-child relationships.
Python
SELECT
Name,
(SELECT
LastName,
(SELECT
AssetLevel,
(SELECT
Description,
SELECT
( LineItemNumber
FROM
WorkOrderLineItems)
FROM
WorkOrders)
FROM
Assets)
FROM
Contacts)
FROM
Account
○ As for child-to-parent relationship queries, also up to five levels of
relationships can be specified in the SOQL statement
■ process records in batches by using a list variable to store the query
results
12
■ Or one record at a time by assigning a single sobject variable instead
○ It is a best practice to perform DML operations on records in batches using a
SOQL for loop
○ Semicolon and comma characters can be used to add filter logic when
querying multi-select picklist fields
○ When merging sObject records, consider the following rules and guidelines:
13
■ Only leads, contacts, cases, and accounts can be merged. See
sObjects That Don’t Support DML Operations.
■ You can pass a master record and up to two additional sObject
records to a single merge method.
■ Using the Apex merge operation, field values on the master record
always supersede the corresponding field values on the records to be
merged. To preserve a merged record field value, simply set this field
value on the master sObject before performing the merge.
● Using the with sharing, without sharing, and inherited sharing
Keywords
○ Inner classes do not inherit the sharing setting of their container class
14
■ Complex business processes not supported by declarative automation
tools
○ An access modifier( public or global) must be used in the declaration of a
top-level class
■ An access modifier is not required in the declaration of an inner class
○ Whether an access modifier has been specified or not, the ‘class’ keyword is
always mandatory
○ The data type of the value returned by an Apex method is required
■
● Trigger
15
○ Before Update trigger
■ Can be used to update field values before a record is saved to the
database
● The record that invoked the trigger has already been saved to
the database (but not yet committed) and becomes read-only
such that setting a value on a field will throw an exception
■ Trigger.new
● contains a list of the new versions of sObject records that is
available in insert, update, and undelete triggers.
■ 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
16
■ isExecuting
● context variable returns true if any code inside the trigger
context is executing
■ Trigger.operationType
● is a trigger variable that returns the context of the executing
DML operation
○ BEFORE_INSERT
○ BEFORE_UPDATE
○ BEFORE_DELETE
○ AFTER_INSERT
○ AFTER_UPDATE
○ AFTER_DELETE
○ AFTER_UNDELETE
17
○ Before insert
○ Using one apex trigger only for each sObject to capture all the event types
and a trigger handler, which is an apex class, to perform the logic required by
the trigger
○ An apex trigger is allowed to invoke another trigger, and there are methods
to prevent unwanted recursions
18
○ An apex trigger may or may not use a future method to perform DML
statements
○ If the execution of one trigger causes one or more additional triggers to be
fired, the triggers are said to be cascading triggers
○ Cascading triggers are part of the same execution context with respect to
governor limits
■ SOQL queries that can be issued to prevent recursion, but does not
set a limit on the number of triggers that can be executed
○ To invoke an Apex trigger when a platform event message is received, it must
be subscribed to the platform event
■ To subscribe to the platform event, the Apex trigger should be created
on the event object type, which ends with the suffix ‘__e’.
19
○
○ Manage Your Platform Event Trigger Subscriptions from the User Interface
■ The Apex trigger needs to stop executing to prevent further issues in
the org without losing any published event messages
● To achieve this, the subscription of the trigger to the platform
event can be suspended, which in this state, does not invoke
the trigger to process any published event messages.
20
○ The @JsonAccess annotation can be used for an Apex class to determine in
which context it is allowed to be serialized or deserialized.
○ For example, to never allow an Apex class to be serialized but allow everyone
to deserialize it, the following annotation can be used:
■ From version 49.0 onwards, the default access for both serialization
and deserialization is ‘saveNamespace’, meaning serialization and
deserialization are allowed as long as the Apex code accessing it is in
the same namespace.
○ When using this operator, the right-hand argument is returned whenever the
left-hand argument returns null
○ The safe navigation operator can be used for replacing explicit checks for null
references and uses the syntax "?".
■ If the left-hand side of the operator evaluates to null, null is returned.
Otherwise, the right-hand side, which can contain a method, variable,
or property, is chained to the left-hand side of the operator and
returned.
21
○
○ Bulk triggers are Apex triggers that support bulk transactions
Describe how to use basic SOSL, SOQL, and DML statements when
working with objects in Apex
22
● As long as each child record can be deleted
○ The undelete operation restores the record associations for parent cases
○ Enables users to view and monitor flows, create new ones, and access any
flows they have permission to modify in Flow Builder
○ It does not offer real-time notifications for flow errors or automatic error
resolution
■ Users can identify flows with errors via the list views but must resolve
these issues manually.
■ One can create targeted error messages for users to explain what
went wrong or how to correct it
■ Error messages can be created for before-save and after-save flows
■ The admin can add this element to the existing record-triggered flow
to display the error message in a window on the overall record page
or as an inline error on the Email field.
23
○ Using the Fault path in the flow to receive an email based on flow resources
would not help the end users correct their mistakes, considering it would be
unrecognizable to them
○ However, a failed flow interview is not saved in all instances. The flow
interview is not saved, for example, if the error came from a flow that is
either inactive, a platform event-triggered flow, from a managed package
(and is not a template), or the error was thrown as a result of an Apex test
method, and more. So, if the flow interview is not saved, then the notification
email does not include a link.
○ A failed flow interview of a screen flow is saved if it is active, for example,
regardless of the element that threw an exception. If the status metadata
field of a flow is ‘Draft’ or ‘InvalidDraft’, then its failed flow interviews are not
saved.
24
○
○ An external object can be created in Salesforce using Salesforce Connect. The
external object enables access to data that resides in the external order
management system. The flow can access and update external object data as
well as Salesforce data. External objects are supported by event processes,
invocable processes, screen flows, and autolaunched flows.
○ A platform-event triggered flow can subscribe to a platform event that is
published by the external system. The flow can then identify the related
external object defined in the org by matching a field in the event message
received.
25
○ Use the System.enqueueJob Method to Specify a Delay in Scheduling Queueable
Jobs
■ Salesforce allows adding a scheduled delay to a queuable job using
the System.enqueuejob() method. The delay value in
minutes(minimum of 0 and maximum of 10) can be passed to the
second parameter of the enqueuejob() method to determine the
delay duration.
● Note that an org-wide default delay for all queuable jobs can
be set in Setup > Apex Setting. Using the System.enqueueJob()
method to delay a job overrides the org-wide default delay for
the job.
● Detecting Duplicate Queueable Jobs
○ To ensure that each queuable Apex job is unique in the processing queue, a
signature can be generated using the QueueableDuplicateSignature class
and stored on the DuplicateSignature property of the AsyncOptions.
○ The QueueableDuplicateSignature class provides the addId(), addInteger(),
and addString() methods for building the signature.
○ These methods can also be ‘combined’ to create the signature.
Java
options.DuplicateSignature = QueueableDuplicateSignature.Builder()
.addId(UserInfo.getUserId())
.addString(record.Id)
.build();
System.enqueueJob(
new
ExampleQueueableJob(), options);
26
○ There is no Array datatype in Apex
○ List
■ List<Account> accList = new List<Account>();
■ Account[] accList = new Account[]{};
■ List<Account> accList = new Account[]{};
● Enums
○ An abstract data type used to contain a predefined set of finite values or
identifiers that cannot be modified at runtime
○ List, set, and map are collection data types in Salesforce used to store data
that represent a collection of primitive or non-primitive values.
● Decimal
○ Used for storing numbers that include a decimal point and is most suitable
for working with currency values
● String
27
○ Address fields
■ On standard objects are compound data types and cannot be directly
modified. Instead, each individual component of the Address field
must be modified.
■
■ The only formula functions that work with Geolocation are ISBLANK,
ISCHANGED, and ISNULL.
○ Private
■ The method or variable is accessible only within the Apex class in
which it is defined
28
○ Protected
■ The method or variable is visible to any inner classes in the defining
Apex class and to the classes that extend the defining Apex class
■ Can not be used on static methods and is only allowed on instance
methods and member variables.
○ Public
■ The method or variable can be used by any Apex in the current
application or namespace
○ Global
■ The method or variable can be used by any Apex code that has access
to the class, not just the Apex code in the current application
■ As it is up to the extending class to provide the body for the method
29
Given a scenario, use declarative functionality and Apex together to
automate business logic
○ Apex methods that can be called from flows or processes must be annotated
with @InvocableMethod. Invocable methods must be static and scoped as
public or global classes
30
expose methods to Aura and Lightning Web components and cache
responses.
○
○ To allow Flow Builder to pass input values (or retrieve output values) to the
invocable method, the necessary class member variables must be defined as
invocable variables by annotating them with @InvocableVariable.
○
31
Given a scenario, identify the implications of governor limits on Apex
transactions
○ A future method can only return void and does not support other return
types
○ Salesforce allows performing DML operations on up to 10,000 records only in
a single transaction.
○ Processing more than 10,000 records will throw a limit exception.
32
○ A recommended solution is to use Batch Apex,
○ Executing the code in a future method or anonymous block cannot bypass
governor limit restrictions.
○ Limits.getDMLRows()
■ Returns the number of records that have been processed using any
DML statement that counts against the DML limits
■ This can be used together with the getLimitDMLRows() method, which
returns the actual limit
○ Limits.getLimitDMLStatements()
■ Returns the number of DML operations that can be called in a single
transaction
○ Limits.getDMLStatements()
■ Returns the number of DML operations that have already been called
○ In addition to DML statements such as insert, update, upsert, delete,
undelete, and merge, other method calls such as Approval.process(),
Database.convertLead(), Database.emptyRecycleBin(), Database.rollback(),
Database.setSavePoint(), EventBus.publish(), and System.runAs() also count
toward the governor limit of the total number of DML statements that can be
issued in a single transaction.
33
○ Apex triggers share the governor limits in a single transaction. This means
that with every DML statement issued, regardless of which Apex trigger
performed the operation, will count toward the same governor limits. Apex
triggers should be purposely written to support bulk operations and help
minimize the number of DML calls.
○ Custom exceptions in Apex can be instantiated using any of the following
options:
■ With a single String argument that specifies the error message:
■ With a single Exception argument that specifies the cause and that
displays in any stack trace:
34
■ With both a String error message and a chained exception cause that
displays in any stack trace:
○ Custom exceptions can be top-level classes, as well as inner classes, and
supports member variables, methods, and constructors
○ A custom exception extends the build-in Exception class and its name should
end with ‘Exception’
○ Custom exceptions and build-in exceptions, except the generic Exception,
can be explicitly thrown.
○ Custom Exception classes can be defined as virtual classes so that they can
be extended by another custom exception class.
○ When catching an exception, it can be rethrown by passing the exception as
a parameter
○
○ NullPointerException
35
○ addError(errMsg) method
■ Can be invoked at the record or field level within the trigger context to
flag a record as invalid
■ It marks a record with a custom error message and prevents any DML
operations from occurring
●
36
■ LimitException and AssertException can not be caught.
○ LimitException:
○ AssertException
○ NullPointerException
○ QueryException
● Ex: when a SOQL query is unable to return exactly one result to
an sObject variable
○ NoAccessException
Describe the relationship between Apex transactions, the save order of
execution, and the potential for recursion and/or cascading
37
■ System and User Defined Validation Rules
■ Duplicate Rules
■ After Triggers
■ Assignment Rules
■ Workflow Rules
○ Execution of post-commit logic, such assending emailswill happenafter all
DML operations are committed to the database
● Workflow rule and before update trigger
○ Ifworkflow rule that updates a fieldandBefore updateapex trigger has
been defined on that object
■ 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.
● Automation execute order when a record is saved
○ After update trigger
○ Assignemnt rules
○ Escalation rules
○ Processes
● More orders
38
Given a scenario, use and apply Apex control flow statments
○ The “switch” control flow statement is capable of handling multiple values in
its “when” blocks as well as ENUM values.
○ By converting the if-else statement into this structure, code becomes easier
to read. Also in the “switch” control flow statement, the variable name doesnt
need to be repeated which helps reduce code size relatively.
○
39