This post is part of the series – Design Pattern in Apex I know it was discussed number of times earlier about Apex Trigger Design Pattern. Below are few excellent posts –
Now the trigger code is very neat and clean. At the same time all our operations against trigger events are moved to handler class.
So now let’s consider few use cases –
Use Case 1 –
While inserting new accounts, if the Account Rating is marked as ‘Hot’, then mark those accounts as Active and make the Customer Priority as ‘Medium’.
Implementation –
To implement the above requirement, what we need to do is simply add the functionality in AccountTriggerHandler.AccountBeforeInsertHandler class. No changes in Apex trigger code is required.
While updating accounts, if Account Name changed, find how many account name changed and print the count.
Implementation –
To implement the above requirement, what we need to do is simply add the functionality in AccountTriggerHandler.AccountBeforeUpdateHandler class. You can do the same in AfterUpdate also. 🙂