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

SF System Exception In Triggerhandler.getHandlerName() :191 #34

Open
rpsherry-starburst opened this issue Aug 3, 2021 · 1 comment
Open

Comments

@rpsherry-starburst
Copy link

rpsherry-starburst commented Aug 3, 2021

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
Copy link
Author

rpsherry-starburst commented Jul 27, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant