Skip to content

Commit

Permalink
Adjusted indents on TriggerHandler.cls. Added variable to store trigg…
Browse files Browse the repository at this point in the history
…er handler name and method to set the name (see kevinohara80#29) to improve performance. Added new constructor to accept trigger handler name. Added test method for new constructor. Updated README.md to show examples of using new constructor.
  • Loading branch information
CoventryOGAdmin committed Nov 27, 2021
1 parent 6809cf2 commit 6255e93
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 237 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ In your trigger handler, to add logic to any of the trigger contexts, you only n
```java
public class OpportunityTriggerHandler extends TriggerHandler {

/* Optional Constructor - better performance */
public OpportunityTriggerHandler(){
super('OpportunityTriggerHandler');
}

public override void beforeUpdate() {
for(Opportunity o : (List<Opportunity>) Trigger.new) {
// do something
Expand All @@ -52,7 +57,9 @@ public class OpportunityTriggerHandler extends TriggerHandler {

private Map<Id, Opportunity> newOppMap;

public OpportunityTriggerHandler() {
/* Optional Constructor - better performance */
public OpportunityTriggerHandler(){
super('OpportunityTriggerHandler');
this.newOppMap = (Map<Id, Opportunity>) Trigger.newMap;
}

Expand Down Expand Up @@ -80,7 +87,9 @@ To prevent recursion, you can set a max loop count for Trigger Handler. If this
```java
public class OpportunityTriggerHandler extends TriggerHandler {

public OpportunityTriggerHandler() {
/* Optional Constructor - better performance */
public OpportunityTriggerHandler(){
super('OpportunityTriggerHandler');
this.setMaxLoopCount(1);
}

Expand All @@ -99,6 +108,11 @@ What if you want to tell other trigger handlers to halt execution? That's easy w
```java
public class OpportunityTriggerHandler extends TriggerHandler {
/* Optional Constructor - better performance */
public OpportunityTriggerHandler(){
super('OpportunityTriggerHandler');
}
public override void afterUpdate() {
List<Opportunity> opps = [SELECT Id, AccountId FROM Opportunity WHERE Id IN :Trigger.newMap.keySet()];
Expand Down
Loading

0 comments on commit 6255e93

Please sign in to comment.