Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big Performance Improvement #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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) {
Expand All @@ -49,7 +54,12 @@ public class OpportunityTriggerHandler extends TriggerHandler {

```java
public class OpportunityTriggerHandler extends TriggerHandler {


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

private Map<Id, Opportunity> newOppMap;

public OpportunityTriggerHandler() {
Expand Down Expand Up @@ -79,7 +89,12 @@ To prevent recursion, you can set a max loop count for Trigger Handler. If this

```java
public class OpportunityTriggerHandler extends TriggerHandler {


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

public OpportunityTriggerHandler() {
this.setMaxLoopCount(1);
}
Expand All @@ -99,6 +114,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
11 changes: 9 additions & 2 deletions src/classes/TriggerHandler.cls
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public virtual class TriggerHandler {
public TriggerHandler() {
this.setTriggerContext();
}

public TriggerHandler(String handlerName) {
this.handlerName = handlerName;
this.setTriggerContext();
}
/***************************************
* public instance methods
***************************************/
Expand Down Expand Up @@ -155,8 +158,12 @@ public virtual class TriggerHandler {

@TestVisible
private String getHandlerName() {
return String.valueOf(this).substring(0,String.valueOf(this).indexOf(':'));
if(String.isBlank(this.handlerName)) {
this.handlerName = String.valueOf(this).substring(0,String.valueOf(this).indexOf(':'));
}
return handlerName;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return handlerName;
return this.handlerName;

}
private String handlerName {get; set;}

/***************************************
* context methods
Expand Down