sfdc-trigger-framework icon indicating copy to clipboard operation
sfdc-trigger-framework copied to clipboard

SF System Exception In Triggerhandler.getHandlerName() :191

Open rpsherry-starburst opened this issue 4 years ago • 1 comments
trafficstars

Hello,

Love this frame work. Been using it recently. I noticed that every now and then my contact object throws a system exception during trigger validation. Specifically Triggerhandler.getHandlerName() :191

Salesforce System Error: 211775977-20872 (-1527031483) (-1527031483)

I opened up a case with sfdc support to see what that means.

They reported that under the hood java was stating:

Subject: 
Unsupported exception when doing a java call from apex
ExtendedMessage: 
Your call to com/salesforce/api/interop/apex/bcl/StringMethods:valueOf resulted in an exception of type: java.lang.IllegalStateException, which we do not wish to bubble up into apex.  Please trap it and convert to a HandledException or ExecutionException

Error : 
java.lang.IllegalStateException: Programmer error: Cannot compare savepoints from two different transactions

Apex Stack Trace At Last Failure:
 	TriggerHandler:getHandlerName():191
 	TriggerHandler:validateRun():186
 	TriggerHandler:run():31
 	__sfdc_trigger/contact_Trigger:invoke():12

Last SOQL query: SELECT Name, Processing_filter_ui_config__c, Processing_filter_soql__c, Filters_json__c, Default_map__c, For_territory__c, For_match__c FROM cls_Object__c WHERE Name IN ('Contact')

Which on my end references this snippet in the TriggerHandler.cls

       // make sure this trigger should continue to run
    @TestVisible
    private Boolean validateRun() {
        if (!this.isTriggerExecuting || this.context == null) {
            throw new TriggerHandlerException(
                'Trigger handler called outside of Trigger execution'
            );
        }
        return !TriggerHandler.bypassedHandlers.contains(getHandlerName());
    }

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

Wondering if anyone else has run into this problem / how they fixed it.

rpsherry-starburst avatar Aug 03 '21 15:08 rpsherry-starburst

I tried Implementing the new version of getHandlerName()

@TestVisible private String getHandlerName() { return this.toString().substringBefore(':'); }

...but kept receiving this error. so my fix went a bit barbarian.

I changed getHandlerName() to a virtual method. That I override in all of my trigger handlers.

TriggerHandler.getHandlerName()

 @TestVisible
  public virtual String getHandlerName() {
    System.debug('Handler Name: TriggerHandler');

    return 'TriggerHandler';
  }

example_triggerHandler.getHandlerName(); Extends TriggerHandler

public override String getHandlerName() {
    return 'example_TriggerHandler';
  }

I will report back if this doesn't solve the problem

rpsherry-starburst avatar Jul 27 '23 16:07 rpsherry-starburst