@TestSetup Method – Testing – Salesforce Certified Platform Developer I Study Guide

9.4 @TestSetup Method Here’s an example that demonstrates the usage of @TestSetup: @isTest private class ContactTriggerTest { @TestSetup static void setupTestData() { // Create a test account Account testAccount = new Account(Name = ‘Test Account’); insert testAccount; // Create a test contact without setting standard field values Contact testContactWithoutValues = new Contact( FirstName = ‘John’, […]

Salesforce Environments – Salesforce Developer Experience (DX) – Salesforce Certified Platform Developer I Study Guide

10.1 Salesforce Environments Developer Pro Sandbox A Developer Pro Sandbox is a dedicated environment for individual developers or small teams. It provides a separate space for development and testing, allowing developers to work independently without affecting other developers’ work. It is typically used for individual development and testing tasks, such as building new features, debugging […]

Test.startTest() and Test.stopTest() Methods – Testing – Salesforce Certified Platform Developer I Study Guide

9.5  Test.startTest() and Test.stopTest() Methods The Test.startTest() and Test.stopTest() methods in Salesforce Apex are used to delineate a specific section of code within a test method. This is useful for isolating and measuring the performance of a specific piece of code and for ensuring that asynchronous code, such as Batch Apex or future methods, is […]

Test Data Factory – Testing – Salesforce Certified Platform Developer I Study Guide

9.3  Test Data Factory Let’s create our test data factory for the given ContactTrigger test class; follow these steps: Step 1: Create the new class ContactFactory in your Developer Console. @isTest public class ContactFactory { public static Contact createContact(String firstName, String lastName) { Contact newContact = new Contact(); newContact.FirstName = firstName; newContact.LastName = lastName; return […]

Try-Catch Method – Testing – Salesforce Certified Platform Developer I Study Guide

9.2 Try-Catch Method In Apex, the Try-Catch method is used to handle exceptions that may occur during the execution of a block of code. It allows you to catch and handle specific types of exceptions, preventing your code from crashing and providing error handling capabilities. If you try to execute the code example as follows […]

How to Write Test Cases – Testing – Salesforce Certified Platform Developer I Study Guide

9.1  How to Write Test Cases Unit tests in Apex are written using the Apex testing framework, which provides a set of classes and methods specifically designed for testing Apex code. These tests are typically written by developers to validate the functionality of their code and ensure that it meets the desired requirements. In Salesforce, […]

Implementing Security. stripInaccessible() Method – Access Control and Permissions – Salesforce Certified Platform Developer I Study Guide

8.3 Implementing Security. stripInaccessible() Method This method allows you to filter records based on the permissions of the current user. It can be used to remove fields and objects that the user does not have access to across a set of records. It´s often used when dealing with collections of records like a list of […]

Execution Context – Access Control and Permissions – Salesforce Certified Platform Developer I Study Guide

8.1 Execution Context In Apex, there are two types of execution contexts such as system execution context and user execution context. User execution context is when a user clicks a button or link, for example, that executes Apex code. When a system event or process executes Apex code, a system execution context is created. Apex […]

Bulk Processing for Large Datasets – Triggers and Bulk Processing – Salesforce Certified Platform Developer I Study Guide

7.3  Bulk Processing for Large Datasets Collections like lists, sets, and maps are essential for bulk processing. They allow you to group and manipulate records efficiently. Fetch required data outside the loop and use collections to match and process records. Utilize bulk DML operations to update, insert, or delete multiple records in a single transaction. […]

Trigger.isBefore 2 – Create Triggers with Context Variables – Triggers and Bulk Processing – Salesforce Certified Platform Developer I Study Guide

To avoid recursive triggers in Apex, you can implement the following approaches as in the following example: \ 1.\ Static Boolean Variable: Create a static Boolean variable, and use it to track whether the trigger has already been executed. Set the variable to true before executing the trigger logic, and reset it to false after […]