0% found this document useful (0 votes)
45 views39 pages

Process Automation and Logic

Uploaded by

mmvj5pdbxf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views39 pages

Process Automation and Logic

Uploaded by

mmvj5pdbxf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

‭Process Automation and Logic - PD1‬

‭17 September 2024‬

‭Identify the capabilities of the declarative process automation features‬

‭●‬ ‭Automation‬

‭○‬ ‭Workflow rules and‬‭processes‬

‭■‬ ‭capable of creating task records at multiple intervals(e.g., after 7 days,‬


‭15 days, etc)‬

‭■‬ ‭Capable of updating the value of a field on a parent record when a‬


‭child record is updated‬

‭●‬ ‭Although A master-detail relationship is required for workflow‬


‭rules.‬

‭○‬ ‭Workflow rules do not (Process Builder can)‬

‭■‬ ‭Capability to submit records for approval or update child records‬

‭○‬ ‭Flow Builder is the primary tool for implementing declarative automation on‬
‭the salesforce platform‬

‭●‬ ‭HTTP Callout‬

‭○‬ ‭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)‬

‭●‬ ‭Run Order of Record-Triggered Flows‬

‭○‬ ‭The ‘Trigger Order’ property is available in the Advanced Properties of a‬


‭record-triggered flow‬

‭■‬ ‭Can be used to specify when the flow is executed in a transaction that‬
‭involves over flows.‬

‭●‬ ‭Deploy Orchestrations with Change Sets‬

‭○‬ ‭Flow Orchestration and all its referenced flows must be activated before they‬
‭can be added as change set components‬

‭○‬ ‭When activated‬

‭■‬ ‭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‬

‭●‬ ‭Improve Agent Interactions with Prebuilt Flows‬

‭○‬ ‭3 prebuilt flows in Salesforce‬

‭■‬ ‭‘Create a Case’:‬

‭●‬ ‭Include Screens, Get Records, Create Records, Decision, and‬


‭Assignment.‬

‭●‬ ‭Manage Record-Triggered Flows‬

‭○‬ ‭Flow Trigger Explorer‬

‭■‬ ‭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.‬

‭●‬ ‭Ways to Send a Slack Notification‬

‭○‬ ‭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.‬

‭Given a scenario, write SOSL, SOQL, and DML statements in Apex‬

‭●‬ ‭Comparison Operators‬


‭○‬ ‭Wildcards‬
‭■‬ ‭The % and _ wildcards are supported for the LIKE operator‬
‭■‬ ‭The % wildcard matches zero or more characters‬
‭■‬ ‭The _ wildcard matches exactly one character.‬
‭○‬ ‭The‬‭IN‬‭clause‬
‭■‬ ‭returns records where the field has an exact match in any of the‬
‭values specified in the IN array‬
‭○‬ ‭LIKE‬
‭■‬ ‭The “LastName LIKE ‘_Ab’” criteria will match three-letter values that‬
‭end in ‘AB’‬
‭○‬ ‭=‬
‭■‬ ‭The “LastName = ‘Ab%’” filter will treat % as a literal character and not‬
‭as a wildcard character‬

‭●‬ ‭SOQL and SOSL Reference‬

‭○‬ ‭COUNT() and COUNT(fieldName)‬

‭■‬ ‭The GROUP BY clause can be used together with the‬


‭COUNT(FileName) aggregate function to return data that groups and‬
‭counts the number of records based on a field value‬

‭■‬ ‭SOQL does not support the wild card character, or asterisk(*), unlike‬
‭SQL‬

‭4‬
‭●‬ ‭SOQL and SOSL Queries‬

‭○‬ ‭SOQL queries‬

‭■‬ ‭Date Literals‬

‭●‬ ‭NEXT_90_DAYS is a date literal in SOQL that refers to all dates‬


‭within the next 90 days.‬

‭■‬ ‭fieldList‬

‭●‬ ‭SELECT fieldList [subquery][...]‬

‭●‬ ‭You can include any of these in the field list:‬

‭○‬ ‭FIELDS(ALL)‬‭—select all the fields of an object.‬

‭○‬ ‭FIELDS(CUSTOM)‬‭—select all the custom fields of an‬


‭object.‬

‭○‬ ‭FIELDS(STANDARD)‬‭—select all the standard fields of‬‭an‬


‭object.‬

‭■‬ ‭Date Formats and Date Literals in WHERE‬

‭●‬ ‭To specify a timezone in a WHERE clause in SOQL, the time‬


‭zone offset is defined at the end of the date-time value.‬

‭●‬ ‭Date or DateTime values in queries are not enclosed in quotes.‬


‭The format syntaxes that can be used for date, time, and time‬
‭zone offset are as follows:‬

‭○‬ ‭YYYY-MM-DDThh:mm:ss+hh:mm (eg.,‬


‭2021-06-30T[Link]+08:00)‬

‭○‬ ‭YYYY-MM-DDThh:mm:ss-hh:mm (eg.,‬


‭2021-06-30T[Link]-08:00)‬

‭○‬ ‭YYYY-MM-DDThh:mm:ssZ (eg., 2021-06-30T[Link]Z)‬

‭5‬
‭○‬ ‭SOSL queries‬

‭■‬ ‭SOSL Syntax‬

‭●‬ ‭[FIND ‘martin’ IN NAME FIELDS RETURNING Lead(Name),‬


‭Contact(Name)]‬

‭■‬ ‭Dynamic SOSL‬

‭●‬ ‭The query() method of the Search class(‬‭[Link]()‬‭)‬‭can‬


‭also be used‬

‭■‬ ‭SOSL Statements‬

‭●‬ ‭Evaluate to a lists of sObjects‬

‭●‬ ‭To store the search results of a SOSL query,‬


‭<List<List<sObject>>> can be used in Apex‬

‭○‬ ‭Each list contains the search results for a particular‬


‭sObject type‬

‭○‬ ‭If no records are returned for a specified sObject type,‬


‭the search results include an empty list for that sObject‬

‭●‬ ‭The objects to search can be specified in the RETURNING‬


‭clause.‬

‭●‬ ‭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‬

‭●‬ ‭SOSL is designed to search for records from one or more‬


‭objects.‬

‭6‬
‭●‬

‭■‬ ‭Optimized SOSL searches‬

‭●‬ ‭To ensure faster SOSL starches‬

‭○‬ ‭Exact phrases should be used, and the search terms‬


‭should be as selective as possible.‬

‭○‬ ‭Search can also be optimized by limiting the search‬


‭scope to specific objects, fields, records owned by the‬
‭searcher, and records within a division, whenever‬
‭applicable.‬

‭●‬

‭●‬ ‭Quoted String Escape Sequences‬

‭○‬ ‭SOQL defines several escape sequences to include special characters in‬
‭queries.‬

‭■‬ ‭\n, \’, \”, \/ \n, \r, \t, \b, \f, \\‬

‭7‬
‭■‬ ‭Like expression only:‬

‭●‬ ‭\_, \%‬

‭●‬ ‭Salesforce Object Search Language (SOSL)‬

‭○‬ ‭LIMIT n‬

‭■‬ ‭If a limit is set on the entire query, results are evenly distributed‬
‭among the objects returns.‬

‭■‬ ‭Limits can also be set per individual object.‬


‭○‬ ‭RETURNING‬
‭■‬ ‭an optional clause that can be used in SOSL queries to specify the‬
‭information that should be returned in the search result‬
‭●‬ ‭Ex: to specify that a SOSL query should return the names of‬
‭Account records only, the following can be used:‬
‭○‬ ‭FIND {search parameter} RETURNING Account(Name)‬

‭●‬ ‭DML Statements vs. Database Class Methods‬

‭○‬ ‭Apex offers two ways to perform DML operations:‬

‭■‬ ‭DML statements or‬

‭■‬ ‭Database class methods.‬

‭8‬
‭■‬ ‭The following helps you decide when you want to use DML statements‬
‭or Database class methods.‬

‭●‬ ‭Use‬‭DML statements‬‭if you want any error that occurs‬‭during‬


‭bulk DML processing to be thrown as an Apex exception that‬
‭immediately interrupts control flow (by using try. . .catch‬
‭blocks). This behavior is similar to the way exceptions are‬
‭handled in most database procedural languages.‬

‭○‬ ‭Ex: insert dataToInsert;‬

‭●‬ ‭Use‬‭Database class‬‭methods if you want to allow partial‬


‭success of a bulk DML operation—if a record fails, the‬
‭remainder of the DML operation can still succeed. Your‬
‭application can then inspect the rejected records and possibly‬
‭retry the operation. When using this form, you can write code‬
‭that never throws DML exception errors. Instead, your code‬
‭can use the appropriate results array to judge success or‬
‭failure. Note that Database methods also include a syntax that‬
‭supports thrown exceptions, similar to DML statements.‬

‭●‬ ‭Database class‬

‭○‬ ‭[Link](recordToInsert, allOrNone)‬

‭■‬ ‭The second parameter of the Database insert method is an optional‬


‭‘allOrNone’ parameter, which specifies whether or not partial success‬
‭is allowed.‬

‭■‬ ‭Does NOT return a Map of results, it returns a List.‬

‭○‬ ‭SaveResult Class‬

‭■‬ ‭When partial success is allowed (allOrNone parameter is false), the‬


‭[Link]() method returns a List of SaveResult objects.‬

‭9‬
‭■‬ ‭The results list corresponds index-by-index to the original list of‬
‭sObject records passed into [Link]().‬

‭■‬ ‭Each SaveResult record contains information about each record's‬


‭insert attempt, such as if it was a success or failure, and a list of errors‬
‭if the record failed to insert.‬

‭●‬ ‭sObjects That Don’t Support DML Operations‬

‭○‬ ‭Profile and Record Type …‬

‭○‬

‭●‬ ‭Callout after DML operations‬

‭○‬ ‭Salesforce does not allow callout to be made after DML operations in the‬
‭same transaction‬

‭■‬ ‭Throw ‘You have uncommitted work pending’ error‬

‭●‬ ‭Using Relationship Queries‬

‭○‬ ‭A join in SOQL will return results from 2 or more standard/custom objects‬

‭○‬ ‭To create a join, or in order to perform a relationship query,‬

‭■‬ ‭The queried objects should be related to each other via a‬


‭parent-to-child or child-to-parent relationship‬

‭10‬
‭○‬ ‭Understanding Relationship Names‬

‭■‬ ‭Dot notation is used to reference fields from parent object (eg: SELECT‬
‭[Link], [Link] FROM Contact), while a nested‬
‭SELECT statement is used to query child records.‬

‭●‬ ‭Dot notation cannot be used to query fields on child records‬

‭○‬ ‭From child record, query parent record.‬

‭■‬ ‭Because there is only one parent exists from this‬


‭child record(dot notation is fine)‬

‭●‬ ‭Nested SELECT statements cannot be used to retrieve parent‬


‭data.‬

‭○‬ ‭From parent record, query child record‬

‭■‬ ‭Because there can be many child record‬


‭exists.(need to have another SELECT statement)‬

‭■‬ ‭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.‬

‭○‬ ‭Query Parent-to-Child Relationships‬

‭■‬ ‭A subquery (a parent-to-child relationship query) is used to retrieve a‬


‭list of related child records for each retrieved parent record and is‬
‭written inside parentheses in the SELECT clause. A subquery’s FROM‬
‭clause uses the child relationship name of the lookup relationship on‬
‭the child. For standard objects, this generally the plural form of the‬
‭object ( ‘Cases’)‬

‭■‬ ‭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‬

‭●‬ ‭Understanding Relationship Query Limitations‬

‭○‬ ‭Up to five levels of relationships are allowed in a parent-to-child relationship‬


‭query where the root object is considered the 1st level.‬

‭○‬ ‭As for child-to-parent relationship queries, also up to five levels of‬
‭relationships can be specified in the SOQL statement‬

‭●‬ ‭SOQL For Loops‬

‭○‬ ‭SOQL for loops can be configured to‬

‭■‬ ‭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‬

‭■‬ ‭SOQL for loops(list format) returns up to a maximum of 200 records‬


‭only during each iteration, the memory heap size is minimized‬

‭●‬ ‭Query Multi-Select Picklists‬

‭○‬ ‭Semicolon and comma characters can be used to add filter logic when‬
‭querying multi-select picklist fields‬

‭○‬ ‭A semicolon is used as a special character to implement AND logic‬

‭■‬ ‭‘AAA;BBB’ means ‘AAA’ AND ‘BBB’‬

‭○‬ ‭A comma is used as a special character to implement OR logic‬

‭■‬ ‭‘AAA’,’BBB’ means ‘AAA’ OR ‘BBB’‬

‭●‬ ‭Merging Records‬

‭○‬ ‭Merge operation can only process up to three records at a time.‬

‭○‬ ‭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.‬

‭■‬ ‭External ID fields can’t be used with merge.‬

‭Given a scenario, follow best practices to write Apex classes and‬


‭triggers‬

‭●‬ ‭Using the with sharing, without sharing, and inherited sharing‬
‭Keywords‬

‭○‬ ‭The default sharing setting for Apex class is‬

‭■‬ ‭Without sharing‬

‭○‬ ‭Inner classes do not inherit the sharing setting of their container class‬

‭●‬ ‭Apex code‬

‭○‬ ‭would be involved‬

‭■‬ ‭Implement web services‬

‭■‬ ‭Email services‬

‭■‬ ‭Complex validation over multiple objects‬

‭14‬
‭■‬ ‭Complex business processes not supported by declarative automation‬
‭tools‬

‭■‬ ‭Custom transactional logic‬

‭○‬ ‭Apex is a server-side programming language‬

‭■‬ ‭Cannot be used to create user interface elements such as button‬

‭●‬ ‭Apex Class Definition‬

‭○‬ ‭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‬

‭○‬ ‭Definition modifiers( virtual, abstract) are optional‬

‭○‬ ‭Whether an access modifier has been specified or not, the ‘class’ keyword is‬
‭always mandatory‬

‭○‬ ‭A class can‬‭extend‬‭from another class and/or implement‬‭multiple interfaces‬

‭●‬ ‭Class Methods‬

‭○‬ ‭The data type of the value returned by an Apex method is required‬

‭○‬ ‭Access modifiers(public or protected) is optional‬

‭○‬ ‭Definition modifiers(virtual and abstract) is optional‬

‭○‬ ‭A method can be defined with multiple, single, or no parameters‬

‭■‬ ‭Parameters of a method are contained in the parentheses of the‬


‭method‬

‭■‬

‭●‬ ‭Trigger‬

‭15‬
‭○‬ ‭Before Update trigger‬

‭■‬ ‭Can be used to update field values before a record is saved to the‬
‭database‬

‭○‬ ‭After Update trigger‬

‭■‬ ‭Not suitable for update field‬

‭●‬ ‭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‬

‭○‬ ‭Before Delete triggers‬

‭■‬ ‭Used when deleting records‬

‭○‬ ‭Also see‬

‭○‬ ‭Trigger Context Variables‬

‭■‬ ‭[Link]‬

‭●‬ ‭contains a list of the new versions of sObject records that is‬
‭available in insert, update, and undelete triggers.‬

‭■‬ ‭[Link]‬

‭●‬ ‭context variable returns a map collection where the key is the‬
‭record Id and the value is the old version of the sObject record‬

‭○‬ ‭Only available in update and delete triggers‬

‭16‬
‭■‬ ‭isExecuting‬

‭●‬ ‭context variable returns true if any code inside the trigger‬
‭context is executing‬

‭○‬ ‭This means that a particular trigger can be tested‬


‭whether it is executing or not with the help of this‬
‭variable‬

‭■‬ ‭[Link]‬

‭●‬ ‭is a trigger variable that returns the context of the executing‬
‭DML operation‬

‭●‬ ‭Available context values are‬

‭○‬ ‭BEFORE_INSERT‬

‭○‬ ‭BEFORE_UPDATE‬

‭○‬ ‭BEFORE_DELETE‬

‭○‬ ‭AFTER_INSERT‬

‭○‬ ‭AFTER_UPDATE‬

‭○‬ ‭AFTER_DELETE‬

‭○‬ ‭AFTER_UNDELETE‬

‭○‬ ‭Trigger Syntax‬‭:‬

‭■‬ ‭trigger TriggerName on ObjectName (trigger_events, trigger_events) {‬


‭code_block}‬

‭●‬ ‭Trigger_events can be a comma-separated list that includes‬


‭one or more of the following events:‬

‭17‬
‭○‬ ‭Before insert‬

‭○‬ ‭After insert‬

‭○‬ ‭Before update‬

‭○‬ ‭After update‬

‭○‬ ‭Before delete‬

‭○‬ ‭After delete‬

‭○‬ ‭After undelete‬

‭●‬ ‭Trigger best practice‬

‭○‬ ‭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‬

‭■‬ ‭This apex trigger is then what is called a logicless 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‬

‭●‬ ‭Cascading Triggers‬

‭○‬ ‭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‬

‭○‬ ‭Salesforce enforces limits on operations such as‬

‭■‬ ‭the number of DML statements and‬

‭■‬ ‭SOQL queries that can be issued to prevent recursion, but does not‬
‭set a limit on the number of triggers that can be executed‬

‭●‬ ‭Apex Trigger and Platform Event‬

‭○‬ ‭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’.‬

‭○‬ ‭Platform events only support‬‭‘after insert’‬‭triggers.‬

‭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.‬

‭●‬ ‭This subscription can be resumed to either start with the‬


‭earliest unprocessed event message when the subscription‬
‭was suspended or process new event messages only.‬

‭●‬ ‭Apex best practices‬

‭○‬ ‭Prevent governor limits from being exceeding‬

‭■‬ ‭Ex: imposed on the number of records that can be retrieved in a‬


‭single transaction‬

‭○‬ ‭DML statements should instead be operated on a group of records to reduce‬


‭the number of DML statements that have to be issued, and prevent‬
‭exceeding the governor limit‬

‭●‬ ‭JsonAccess Annotation‬

‭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:‬

‭■‬ ‭@JsonAccess(serializable=’never’ deserializable-’always’).‬

‭■‬ ‭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.‬

‭●‬ ‭Null Coalescing Operator‬

‭○‬ ‭Null coalescing operation (??)‬

‭■‬ ‭Operates in the syntax <left-hand argument> ?? <right hand‬


‭argument>‬

‭○‬ ‭When using this operator, the right-hand argument is returned whenever the‬
‭left-hand argument returns null‬

‭●‬ ‭Safe Navigation Operator‬

‭○‬ ‭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‬

‭○‬ ‭Bulk triggers are Apex triggers that support bulk transactions‬

‭■‬ ‭Ex: data imports‬

‭■‬ ‭Bulk API calls‬

‭■‬ ‭Bulk DML operations‬

‭■‬ ‭Mass action‬

‭●‬ ‭Changing record owners‬

‭●‬ ‭Deleting records in bulk‬

‭Describe how to use basic SOSL, SOQL, and DML statements when‬
‭working with objects in Apex‬

‭●‬ ‭Deleting Records‬


‭○‬ ‭Salesforce only restores lookup relationships that have not been replaced‬
‭○‬ ‭Undelete can also restore opportunity-quote associations‬
‭○‬ ‭Cascading deletions are supported‬
‭■‬ ‭If a parent record is deleted, its children are automatically deleted‬

‭22‬
‭●‬ ‭As long as each child record can be deleted‬
‭○‬ ‭The undelete operation restores the record associations for parent cases‬

‭Identify the capabilities of the declarative process automation features‬

‭●‬ ‭Capable of automatically updating field values on child records when a‬


‭parent record is modified‬
‭○‬ ‭Flow Builder and Process Builder are declarative tools that are capable of‬
‭updating related records such as child records‬
‭○‬ ‭Apex trigger can be used for more complex operations‬
‭●‬ ‭Manage Your Flows More Efficiently with the Automation Lightning App‬

‭○‬ ‭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.‬

‭●‬ ‭Flow element‬

‭○‬ ‭Custom Error Message‬

‭■‬ ‭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‬

‭○‬ ‭Screen element cannot be added to a record-triggered flow.‬

‭●‬ ‭Record-triggered Flow Test‬

‭○‬ ‭Salesforce allows creating tests in Flow Builder specifically for‬


‭record-triggered flows‬

‭○‬ ‭To manage flow tests‬

‭■‬ ‭‘View Tests’ button is used‬

‭●‬ ‭Debug Failed Flows More Easily‬

‭○‬ ‭When an active screen flow, record-triggered flow, scheduled-triggered flow,‬


‭or autolaunched flow with no trigger launches and encounters an error, the‬
‭failed flow interview is saved in the org. The notification email that contains‬
‭details of the error includes a link that allows the recipient to access the‬
‭saved flow interview in Flow Builder and debug the flow more efficiently‬

‭○‬ ‭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‬
‭○‬

‭●‬ ‭Salesforce Connect‬

‭○‬ ‭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.‬

‭Declare variables, constants, methods, and use modifiers and Apex‬


‭interfaces‬

‭●‬ ‭Queueable Apex‬


‭○‬ ‭To specify the maximum stack depth of a queueable job‬
‭■‬ ‭MaximumQueueableStackDepth property of the AsyncOptions class‬
‭can be used‬

‭25‬
‭○‬ ‭Use the [Link] Method to Specify a Delay in Scheduling Queueable‬
‭Jobs‬
‭■‬ ‭Salesforce allows adding a scheduled delay to a queuable job using‬
‭the [Link]() 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 [Link]()‬
‭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‬

AsyncOptions options =‬‭


‭ new‬‭
AsyncOptions();‬

[Link] = [Link]()‬

.addId([Link]())‬

.addString([Link])‬

.build();‬

[Link](‬
‭ new‬‭
‭ ExampleQueueableJob(), options);‬

‭●‬ ‭Declaring a collection variable‬

‭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‬

‭○‬ ‭Example use case‬

‭■‬ ‭Specifying a group of constants‬

‭■‬ ‭Names of the days of the week‬

‭■‬ ‭Names of the months of the year‬

‭■‬ ‭Names of the seasons‬

‭○‬ ‭List, set, and map are collection data types in Salesforce used to store data‬
‭that represent a collection of primitive or non-primitive values.‬

‭■‬ ‭Collections may be modified at any time during a transaction.‬

‭●‬ ‭Decimal‬

‭○‬ ‭Used for storing numbers that include a decimal point and is most suitable‬
‭for working with currency values‬

‭●‬ ‭String‬

‭○‬ ‭Any set of characters surrounded by single quotes‬

‭●‬ ‭Compound Field Considerations and Limitations‬

‭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.‬

‭■‬

‭○‬ ‭Geolocation Custom Field‬

‭■‬ ‭Geolocation is a compound data type consisting of 2 components‬

‭●‬ ‭Latitude and longitude‬

‭■‬ ‭A geolocation field can either be completely blank or it must have‬


‭both the latitude and longitude fields filled in.‬

‭■‬ ‭Because Geolocation is a compound data type, each of its‬


‭components must be accessed separately for evaluation using a‬
‭numeric data type such as a Double or Decimal.‬

‭■‬ ‭The only formula functions that work with Geolocation are ISBLANK,‬
‭ISCHANGED, and ISNULL.‬

‭■‬ ‭Equality or comparison operators cannot be used with geolocations.‬

‭●‬ ‭Access Modifier‬

‭○‬ ‭Private‬

‭■‬ ‭The default access modifier‬

‭■‬ ‭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‬

‭●‬ ‭Apex Class Definition‬

‭○‬ ‭Virtual method‬

‭■‬ ‭Contains a body that can be overridden by an extending class‬

‭○‬ ‭Abstract method‬

‭■‬ ‭Only contains a signature and has no body‬

‭■‬ ‭As it is up to the extending class to provide the body for the method‬

‭○‬ ‭Virtual classes cannot contain abstract methods‬

‭○‬ ‭Only abstract classes can contain abstract methods‬

‭■‬ ‭Abstract classes are allowed to contain virtual methods‬

‭29‬
‭Given a scenario, use declarative functionality and Apex together to‬
‭automate business logic‬

‭●‬ ‭Interview Class‬


‭○‬ ‭There are two ways to invoke a Flow from Apex:‬
‭■‬ ‭[Link].[FlowName](params).start();‬
‭●‬ ‭Can be instantiated as type [Link].[FlowName]‬
‭■‬ ‭[Link](‘[FlowName]’, params).start();‬
‭●‬ ‭Can be instantiated as type [Link]‬

‭●‬ ‭A record-triggered flow can be configured to launch when a record is deleted‬


‭○‬ ‭Apex trigger can also meet the requirements most of the time‬
‭●‬ ‭An assignment rule is used to automatically assign leads or cases to users based on‬
‭specified conditions‬
‭●‬ ‭Validation rules cannot be used on record deletions‬
‭●‬ ‭InvocableMethod Annotation‬

‭○‬ ‭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‬

‭○‬ ‭@InvocableClass is not a valid class annotation in Apex.‬

‭○‬ ‭@AuraEnabled(cacheable=true) is a valid method annotation but does not‬


‭impact a method’s ability to be called by a flow. This annotation is use to‬

‭30‬
‭expose methods to Aura and Lightning Web components and cache‬
‭responses.‬

‭○‬

‭●‬ ‭InvocableVariable Annotation‬

‭○‬ ‭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.‬

‭○‬ ‭The @InvocableVariable annotation is used to define a class variable as an‬


‭input or output parameter for an @InvocableMethod action. An invocable‬
‭variable, which can be a primitive value, sObject, a list or a list of lists of‬
‭primitives, sObjects, Apex class objects, or collections, must be defined as a‬
‭global or public variable.‬

‭○‬

‭31‬
‭Given a scenario, identify the implications of governor limits on Apex‬
‭transactions‬

‭●‬ ‭Execution Governors and Limits‬


‭○‬ ‭The number of SOQL queries‬‭allowed in a(synchronous)‬‭transaction is up to‬
‭100‬
‭■‬ ‭List<object> items = [SELECT…….];‬
‭○‬ ‭DML operation‬‭in a single transaction: 150‬
‭■‬ ‭Insert data‬
‭■‬ ‭Delete data‬
‭■‬ ‭[Link](data)‬
‭○‬ ‭When limit Exceed, Exception will throw‬
‭■‬ ‭The‬‭entire transaction‬‭will be rolled back such that‬‭no records will‬
‭be updated‬
‭■‬ ‭Its best practice to avoid SOQL queries and DML statements inside‬
‭FOR looks to prevent transactions from reaching the governor limits.‬
‭○‬ ‭The‬‭total number of records that can be retrieved‬‭by a SOQL query‬‭in a‬
‭single transaction is limited to 50,000‬
‭●‬ ‭Future Annotation‬

‭○‬ ‭@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‬

‭○‬ ‭A future method cannot invoke another future method‬

‭●‬ ‭Batch Apex‬

‭○‬ ‭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,‬

‭■‬ ‭Which will automatically process the records in batches of‬


‭200(default) records where each batch execution is considered a‬
‭distinct transaction.‬

‭○‬ ‭Executing the code in a future method or anonymous block cannot bypass‬
‭governor limit restrictions.‬

‭●‬ ‭Limits Class‬

‭○‬ ‭[Link]()‬

‭■‬ ‭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‬

‭○‬ ‭[Link]()‬

‭■‬ ‭Returns the number of DML operations that can be called in a single‬
‭transaction‬

‭○‬ ‭[Link]()‬

‭■‬ ‭Returns the number of DML operations that have already been called‬

‭●‬ ‭Apex Governor Limits‬

‭○‬ ‭In addition to DML statements such as insert, update, upsert, delete,‬
‭undelete, and merge, other method calls such as [Link](),‬
‭[Link](), [Link](), [Link](),‬
‭[Link](), [Link](), and [Link]() 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.‬

‭Implement exception handling in Apex, including custom exceptions as‬


‭needed‬

‭●‬ ‭Returned Database Errors‬


‭○‬ ‭Partial processing returns of an insert or update operation in an array of‬
‭[Link]‬‭objects‬
‭■‬ ‭Loop through the array and determine which records failed or‬
‭succeeded by using the isSuccess method of the SaveResult object‬
‭■‬ ‭getErrors method is then used to get error information on the records‬
‭that failed.‬
‭●‬ ‭Create Custom Exceptions‬

‭○‬ ‭Custom exceptions in Apex can be instantiated using any of the following‬
‭options:‬

‭■‬ ‭With no arguments:‬

‭●‬ ‭new MyException();‬

‭■‬ ‭With a single String argument that specifies the error message:‬

‭●‬ ‭new MyException(‘Error Message’);‬

‭■‬ ‭With a single Exception argument that specifies the cause and that‬
‭displays in any stack trace:‬

‭●‬ ‭new MyException(e);‬

‭34‬
‭■‬ ‭With both a String error message and a chained exception cause that‬
‭displays in any stack trace:‬

‭●‬ ‭new MyException(‘Error Message’, e);‬

‭○‬ ‭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‬

‭○‬

‭●‬ ‭Catching Different Exception Types‬

‭○‬ ‭NullPointerException‬

‭■‬ ‭When String data type is initialized with no value assignment‬

‭●‬ ‭It defaults to null.‬

‭●‬ ‭SObject Class‬

‭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‬

‭●‬

‭●‬ ‭Message Class‬

‭○‬ ‭When an exception is caught in an Apex trigger, the‬‭addError‬‭() method can‬


‭be used to display a custom message on the user interface for the end user.‬

‭●‬ ‭Exception Class and Built-In Exceptions‬

‭○‬ ‭The‬‭generic Exception‬‭can be used to handle almost‬‭all Exception types‬

‭36‬
‭■‬ ‭LimitException and AssertException can not be caught.‬

‭○‬ ‭LimitException:‬

‭■‬ ‭When governor limits are exceeded‬

‭○‬ ‭AssertException‬

‭■‬ ‭Apex unit tests when an assertion statement fails‬

‭○‬ ‭NullPointerException‬

‭■‬ ‭When a null variable is being dereferenced‬

‭○‬ ‭QueryException‬

‭■‬ ‭Due to issues directly related to SOQL‬

‭●‬ ‭Such as assigning a single sObject variable to a query result‬


‭that contains either no records(null) or multiple‬
‭records(collection)‬

‭●‬ ‭Ex: when a SOQL query is unable to return exactly one result to‬
‭an sObject variable‬

‭○‬ ‭NoAccessException‬

‭■‬ ‭Unauthorized user attempts to access a secured record‬

‭Describe the relationship between Apex transactions, the save order of‬
‭execution, and the potential for recursion and/or cascading‬

‭●‬ ‭Triggers and Order of Execution‬


‭○‬ ‭When record is saved, salesforce performs a number of events in a certain‬
‭order‬
‭■‬ ‭System Validation Rules‬
‭■‬ ‭Before Triggers‬

‭37‬
‭■‬ ‭System and User Defined Validation Rules‬
‭■‬ ‭Duplicate Rules‬
‭■‬ ‭After Triggers‬
‭■‬ ‭Assignment Rules‬
‭■‬ ‭Workflow Rules‬
‭○‬ ‭Execution of post-commit logic, such as‬‭sending emails‬‭will happen‬‭after all‬
‭DML operations are committed to the database‬
‭●‬ ‭Workflow rule and before update trigger‬
‭○‬ ‭If‬‭workflow rule that updates a field‬‭and‬‭Before update‬‭apex 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‬

‭○‬ ‭Duplicate rules‬

‭○‬ ‭Assignment rules‬

‭○‬ ‭Auto-response rules‬

‭○‬ ‭Workflow rules‬

‭○‬ ‭Escalation rules‬

‭○‬ ‭Roll-up summary calculations‬

‭○‬ ‭Entitlement rules‬

‭38‬
‭Given a scenario, use and apply Apex control flow statments‬

‭●‬ ‭Switch Statements‬

‭○‬ ‭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‬

You might also like