We have a problem in our organization and I was hoping for some advice from you on how to best tackle this.

We have a handler class that makes a callout to a Master Data Management system for account validation. That handler class is perfectly covered by it's own tests that utilize Mocking of the outbound call.

Now our business process dictates that we need to do a check every time an Account is created or updated, so we invoke that callout from an Account After trigger.

Now we run into a problem as any testmethod we have in the system that tries to construct an Account for unit testing purposes triggers the outbound callout and fails with a Fatal error: testmethods cannot invoke callouts.

Can somebody give us a hint on how to best properly deal with this?

Best regards, Ivar

  • How did you implement async callout from trigger? Do you use future annotation, implement Queueable interface? – Oleksandr Berehovskyi Nov 28 '17 at 13:01
  • It is @future but not queueable – Ivar Gunnarsson Nov 28 '17 at 13:09

In your trigger handler class AccountTriggerHandler create static field

private static Boolean skipCallout = Test.isRunningTest();

and then before making a callout check:

    // do callout
| improve this answer | |
  • Thanks Alexander! We were thinking along those lines. Good to get confirmation by a third party! – Ivar Gunnarsson Nov 28 '17 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.