9 Components of a Solid SEO Marketing Strategy

Some business owners avoid SEO marketing because the process seems to be complicated. They give more importance to traditional marketing strategies, which do not bring as many benefits as SEO. While…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Triggers and Helper Class

Triggers are used to capture events on any DML operation and perform custom logic implementation on that event. The Salesforce’s best coding practices suggest that we should have only one Trigger on an object and a Helper class for handling the events of trigger and methods to perform the required custom implementation. So in this article, I’ll explain how to work with the Triggers and Helper Class and use the optimal way to code and use the best coding practices.

First of all, we create only one trigger for an object and use the trigger context variables to differentiate the DML events.

Trigger events can be a comma-separated list of one or more of the following events as described in code.

Just to give an idea to newcomers, here is the list of Trigger Context Variables:

That’s all the Trigger context variables that you’ll be using in general tasks.

We capture and differentiate all the trigger events with the help of the Switch and Trigger.operationType context variable.

In those event capturing conditions we call methods of Helper class. Now we will shift over to Helper Class. The concept behind having a helper class is to have all the logic outside trigger for reusability and I use it to basically cover the code easily with Test class. As it’s easy to find a test class for a class then a test class for the trigger. Moreover, we can even create sub-methods for writing logic which can be used by other methods in the class.

We are capturing the context of the account before and after any DML operation through trigger.newMap and trigger.oldMap. It's good to use map rather than a list to capture the context of object.

Fun part:

Question for the ones who have a piece of good knowledge of Salesforce. Can we use Trigger Context variables in an apex class? If yes then how? If no then why? Do think twice before you answer.

Add a comment

Related posts:

Clustering with Quad Trees

Have you ever opened an app with a map view and it was cluttered with thousands of locations? Fortunately, there is a great solution to this problem called Map Clustering. Annotations in the map-view…

Psicologi in cerca di psicologie

Gran parte della mia vita lavorativa si è svolta in ambito aziendale e, anche senza declamarlo né aspettarmi che venisse conclamato, l’ho vissuta come psicologo quale fui assunto ormai quasi 35 anni…

Using Antibodies to Override Immune Checkpoints and Brakes in Cancer Therapy

Many of the most exciting new anti-cancer drugs are antibodies that target the immune system. The goal is to turn on the body’s natural defenses against abnormal cells. Several new drugs override the…