Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Salesforce Apex Trigger & Test Class: Hands-On Scenarios
Rating: 4.7 out of 5(81 ratings)
930 students

Salesforce Apex Trigger & Test Class: Hands-On Scenarios

Master Salesforce Apex triggers : Build automated business processes with Apex triggers in Salesforce
Last updated 2/2023
English
English [Auto],

What you'll learn

  • Write Apex triggers that execute before or after specific database events (e.g., insert, update, delete).
  • Use Apex triggers to perform custom actions such as validating data, updating related records, and sending emails.
  • How to write Apex test methods that test your Apex triggers and classes.
  • How to use the @testSetup annotation to create test data that can be used by multiple test methods in an Apex test class.

Course content

3 sections42 lectures8h 50m total length
  • Introduction to Apex Trigger4:59

    Learn how to automate Salesforce processes with Apex triggers, using before and after events on standard and custom objects. Understand trigger syntax and events like before insert and after update.

  • Creating Apex Trigger2:43

    Create an apex trigger on the account object with a before insert event, add system.debug messages, and test by inserting an account to review the logs in Salesforce.

  • Trigger Context Variables6:51

    Explore trigger context variables such as is executing, is insert, is update, is delete, is before, is after, undelete, and the new and old lists and maps.

  • Before Insert Vs After Insert10:02

    Explore before insert and after insert triggers for accounts, updating rating to hot or cold based on industry. Create related opportunities automatically on account insert using trigger.new data.

  • Before Update Vs After Update15:46

    Explore before update and after update trigger events on account records, updating the description when the phone changes and syncing the new phone to related opportunities.

  • Before Delete Vs After Delete14:15

    Implement before delete and after delete scenarios in a Salesforce Apex trigger on the employee object. Prevent deletion of active employees and update the related account's employee count after deletion.

  • After Undelete7:59

    Learn how after undelete fires, undeleting an employee restores records, activates the employee, and updates the account's employee count through a Salesforce apex trigger flow.

  • All Before Events Together8:30

    Apply before insert, update, and delete on the account to set rating from industry, update description when the phone changes, and block deletes of active accounts with an error.

  • All After Events Together17:46

    Update accounts' annual revenue automatically by summing opportunity amounts on after insert, after update, and after delete using an Apex trigger and handler.

  • Apply Validation through Trigger5:20
  • Learning About Database Class & addError() Method in Apex Trigger15:37

    Explore database class methods and the addError method in an apex trigger, comparing with DML and implementing try/catch to handle missing fields during account and opportunity creation.

  • Prevent Recursion in Trigger8:29

    Learn how to prevent recursion in an Apex trigger after update by using a prevent recursion class with a static firstCall flag, so update logic runs only once.

  • Triggers and Order of Execution7:12

    Explore triggers and order of execution in Salesforce, covering declarative and Apex automation, before/after events, validations, flows, duplicate rules, rollup summaries, and post-commit logic.

Requirements

  • Familiarity with the Salesforce platform and the data model. This could include an understanding of objects, fields, relationships, and the Salesforce user interface.
  • Basic programming skills. While Apex is a proprietary language, it is similar to Java and C# in many ways. Familiarity with concepts such as variables, loops, and control structures will be helpful.
  • Experience with the Salesforce development environment, including the use of the Developer Console.

Description

This course is designed for Salesforce developers who want to learn about Apex Triggers, Apex Tests, and the power of custom validation in Salesforce. Whether you are a beginner or have some experience, this course will give you a solid foundation in Apex Triggers and help you become an expert.


You will learn how to create Apex Triggers, understand context variables, and master the difference between Before and After events such as Before Insert, Before Update, and Before Delete. You will also learn about the order of execution and how to prevent recursion in your triggers.


The course also covers Apex Tests and how to write positive and negative test cases in a test class. You will learn about sObjects and how to create a test class for your triggers. The course includes scenarios, such as creating related contacts, updating related opportunities, and applying custom validation on opportunity records.


We will  cover many industry ready practicals, such as:

  1. Populating the rating as "Hot" on account creation if the industry is Media or Energy

  2. Populating the description on opportunity creation based on the amount value

  3. Copying the billing address to the shipping address on account creation

  4. Creating a related contact on account insertion

  5. Creating a related opportunity on account insertion

  6. Populating the latest case number on account on case creation

  7. Populating the latest opportunity amount on account on opportunity creation

  8. Creating a contact or opportunity based on the user's choice when an account is created

  9. Updating the description on account when the phone field is updated

  10. Copying the billing address to the shipping address on account insert or update

  11. Updating the related contacts on account update using a map or parent-child SOQL

  12. Creating a task on opportunity when the stage is updated

  13. Updating the related opportunity when an account is updated

  14. Applying custom validation in Apex Trigger and using try & catch in the test class

  15. Applying custom labels in Apex Trigger and test class

  16. Preventing the update of accounts created 7 days ago from today

  17. Applying custom validation on opportunity record creation

  18. Applying custom validation while updating an opportunity record

By the end of this course, you will have a strong understanding of Apex Triggers and Apex Tests and be able to apply custom validation in Salesforce. Sign up now and take the first step towards becoming a Salesforce trigger expert!

Who this course is for:

  • Salesforce administrators who want to learn how to write custom code to automate business processes or to perform custom actions when data is changed in Salesforce.
  • Software developers who are familiar with other programming languages and want to learn how to develop custom solutions on the Salesforce platform.
  • Anyone who is preparing for the Salesforce Platform Developer I certification exam, as Apex triggers and test classes are covered in the exam.
  • Anyone who is interested in learning how to write custom code on the Salesforce platform and ensure that it is working correctly would benefit from taking an Apex triggers and test classes course.