Usually, when we write Apex Triggers, we write the trigger and implement the logic in the same place.
Let’s say you created a trigger to automate the process of updating fields on the Account object when a specific condition is met, such as when account revenue exceeds a certain amount, then the account priority is set to High.
Instead of writing this logic directly inside the trigger, we will use the Trigger helper class to keep the code clean, reusable, and easy to manage.
In the tutorial, we will learn about the Trigger helper class in Salesforce. In this, I will explain how the trigger helper class helps us write logic and triggers neatly and cleanly, which is the best practice for writing triggers in Salesforce.
Trigger Helper Class in Salesforce
When we create a trigger and write the different methods, trigger events, and logic in the trigger class itself, we don’t know which method will execute first because there is no defined order for implementing the methods.
To avoid this, we create the helper class, which is a regular Apex class. In that class, we develop all the methods and implement the logic that we want to execute.
After creating the helper class, we need to create the trigger, and within the trigger, we can call the methods in the desired order to execute. The trigger includes various trigger events, such as ‘before insert’ and ‘after update’, and processes the logic relevant to each event.
Implement the Trigger Helper Class in Salesforce Apex
One trigger per object is the best practice for implementing triggers in Salesforce Apex. If we develop multiple triggers for a single object, we have no way of controlling the order in which they execute.
Syntax: Apex Trigger Helper Class in Salesforce
The helper class is a simple Apex class that defines various methods and implements the necessary logic to fulfill our functionality.
public class TriggerHelper {
public static void FirstMethod(List<Account> newAccounts) {
// Enter Logic;
}
public static void SecondMethod(List<Account> updatedAccounts, Map<Id, Account> oldAccountMap) {
// Enter Logic;
}
}Syntax: Apex Trigger in Salesforce
Now, in the Apex trigger, we need to call the methods that we created in the helper class, and you can call the method in the execution order you require.
trigger AccountTrigger on Account ( before insert, after update ) {
AccountTriggerHelper.SecondMethod ( Trigger.new );
AccountTriggerHelper.FirstMethod( Trigger.new, Trigger.oldMap );
}Create Apex Trigger Helper Class in Salesforce
First, I will explain how to create an Apex trigger helper class in Salesforce and where the actual logic of the trigger is implemented.
For example, we need to automate the process of automatically updating all account-related contacts’ level_c field values to ‘Primary‘ when the account subscription_type_c is updated to ‘Platinum‘ using the Apex trigger.
Here, you need to create a regular Apex class and then implement the methods using the desired logic to automate the process.
To create the class, go to Setup → Developer Console -> File -> New -> Apex Classes → and then write the Apex class with the required logic.

Then, in the for each loop, created an instance of the account object and assigned a newAccounts variable, which is a list of records that the user will update in the account object.
In the if condition, we checked whether the subscription type is equal to ‘platinum’ and then created a list of contacts that returns only the related contacts of the current account, which you will update.
Again, I created a for loop that iterates over related accounts and changed the level field value to ‘primary’ in the contact object. Add the record to the list and update the list outside the for loop.
public class AccHelperClass {
public static void updateRelatedContacts (List<Account> newAccounts) {
List<Contact> contactsToUpdate = new List<Contact>();
for (Account acc : newAccounts) {
if ( acc.Subscription_Type__c == 'Platinum' ) {
List<Contact> relatedContacts = [ SELECT Id, Level__c FROM Contact WHERE AccountId = :acc.Id ];
for ( Contact contact : relatedContacts ) {
contact.Level__c = 'Primary';
contactsToUpdate.add(contact);
}
}
}
if ( !contactsToUpdate.isEmpty() ) {
update contactsToUpdate;
}
}
}Create an Apex Trigger Class in Salesforce
The trigger handler is the Apex Trigger class, where we can call different methods to execute the logic that we implemented in the helper class.
First, we need to create an Apex Trigger on the Account object and add the relevant events to the trigger to determine when it should execute.
Here, I added an if condition to check whether, using the context variable, we are calling events, which are isAfter and isUpdate. Then, using the helper class name, call the methods in the order you want to execute.
After that, we have also created another helper class to send an email when a new account is created. That class also needs to be called here. As the email should go after account creation, so here we used a Trigger.isAfter && Trigger.isInsert context variables.
trigger CallAccHelperClass on Account (after insert) {
if ( Trigger.isAfter && Trigger.isUpdate ) {
AccHelperClass.updateRelatedContacts ( Trigger.new );
}
}Proof of Concept:
Before updating the subscription type field on the account object, you can see that the related contact’s level is set to secondary.
I will update the subscription type to platinum, and let’s see whether the contact level field can be set to primary automatically.

As I update the subscription type to platinum from the account object, the level field of the contact object will automatically change to primary.

Conclsuion
I hope you now have an idea about the trigger helper class in Salesforce. In that, I explained the trigger helper class. Then, we have seen the syntax for declaring a trigger helper class and the Apex trigger.
After that, using an example, I explained how to create an Apex trigger helper class and call the helper class in a Salesforce trigger.
You may like to read:
- Apex Triggers in Salesforce
- Logical and Looping Statements in Salesforce Apex Programming
- Polymorphism in Salesforce Apex
- Inheritance in Salesforce Apex

Shubham is a Certified Salesforce Developer with technical skills for Building applications using custom objects, approval processes, validation rule salesforce flows, and UI customization. He is proficient in writing Apex classes, triggers, controllers, Apex Batches, and bulk load APIs. I am also familiar with Visualforce Pages and Lighting Web Components. Read more | LinkedIn Profile