4.2 Introducing trigger handler class

Why do we want a Trigger handler class

If you think about the code we wrote in 3.4 Write a more difficult trigger and 4.1 Write an advanced trigger . Both triggers are on Transaction__c object. In the previous examples, we have put them into two separate triggers. But this is not the best practice. In Salesforce, it is always good to have one trigger only for each SObject. The reason is, the execution sequence of each independent trigger is always undefined. So it can cause unpredictable behaviour if we have multiple triggers.

• • •

4.1 Write an advanced trigger

The scenario

Our customers can put a balance in our accounts now. They can have a balance in our system. So, now, for every purchase they made, we will need to subtract that amount  from their current balance.

• • •

How does setRedirect work in Visualforce

What is setRedirect

SetRedirect() is a method of PageReference class. When a PageReference value is used as a return value for a commandButton or actionFunction method, the setRedirect() value defines whether it is a client-side redirect or a server-side forward. According to Salesforce document here:

• • •

How does contains work for a set of objects

The question

In Apex, we all know that set can’t have duplicate values. And a set can tell whether it contains a certain element or not. However, things got complicated when the set is composed of objects (or SObjects). When you change a field of the object record, the set won’t recognize the same record any more. It just refuse to think it contains such an element.

• • •