5

Our CI (Continuous Integration) build has started failing today on the sfdx force:source:push with this error:

cvnp.ContentDocumentLinkTrigger: System.LimitException: Can only throw this exception type from VisualForce or Aura context

where in the code the trigger calls there are instances of e.g. AuraHandledException thrown, but they are many classes away from the trigger. Also the errors are reported on content assets:

TYPE   PROJECT PATH                                                    PROBLEM
─────  ──────────────────────────────────────────────────────────────  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error  force-app/main/default/contentassets/homepagehero.asset         cvnp.ContentDocumentLinkTrigger: System.LimitException: Can only throw this exception type from VisualForce or Aura context
Error  force-app/main/default/contentassets/loginPageBackground.asset  cvnp.ContentDocumentLinkTrigger: System.LimitException: Can only throw this exception type from VisualForce or Aura context
Error  force-app/main/default/contentassets/logo.asset                 cvnp.ContentDocumentLinkTrigger: System.LimitException: Can only throw this exception type from VisualForce or Aura context

If you have experienced this error and have a fix let me know what the fix is. But seems like it might be a platform bug.

6
  • Is the exception thrown while Trigger.isRunning = true?
    – sfdcfox
    Commented Mar 26, 2020 at 15:24
  • @sfdcfox There is no guard of that nature in the code so yes it would be. Note that these errors happen when the code is deployed: surely the deploy-time checking hasn't suddenly got extremely good at source code analysis?
    – Keith C
    Commented Mar 26, 2020 at 15:35
  • 1
    I think it's a new feature. It doesn't "make sense" to throw an AuraHandledException in a trigger, since the caller might not be a UI. I know they've been shoring up their exception handling in the last few releases, this might be something that was previously a bug?
    – sfdcfox
    Commented Mar 26, 2020 at 15:44
  • I'll do some asking/research on this.
    – sfdcfox
    Commented Mar 26, 2020 at 15:47
  • Thanks, I'll add in the Trigger.isExecuting guard in case that is enough to fix it and comment back.
    – Keith C
    Commented Mar 26, 2020 at 15:58

1 Answer 1

3

Thanks to sfdcfox, I can now understand the cause of the problem.

With the Trigger.isExecuting check in, I'm now getting the real error:

Error  force-app/main/default/contentassets/homepagehero.asset
cvnp.ContentDocumentLinkTrigger: execution of AfterInsert
caused by: cvnp.SystemErrorException:
Event type cvnp__FakeBaseEvent__c not found
Class.cvnp.Context: line 241, column 1
Class.cvnp.Context: line 229, column 1
Class.cvnp.ProductAdapter.__sfdc_EVENT_TYPE: line 26, column 1
Class.cvnp.ProductAdapter.eventType: line 120, column 1
Class.cvnp.ProductAdapter.handles: line 115, column 1
Class.cvnp.ProductAdapter.instanceFor: line 76, column 1
Class.cvnp.ContentDocumentLinkHandler.Documents.<init>: line 38, column 1
Class.cvnp.ContentDocumentLinkHandler: line 85, column 1
Class.cvnp.ContentDocumentLinkHandler: line 72, column 1

rather than that real error being masked by the complaint about the invalid exception type.

Per usual, it was my code change that broke it, and me using the wrong exception type that obscured the problem.

1
  • Glad I could help point you in the right direction. 😊
    – sfdcfox
    Commented Mar 26, 2020 at 18:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .