I need to query an external Object from Contact Trigger. If records are present in the external object, then we have to update the contact. Otherwise we have to create the contact.

Now, my issue is that if I try to query the external object records, it gives me the following error

Apex trigger AccountTrigger caused an unexpected exception, contact your administrator: AccountTrigger: execution of AfterUpdate caused by: System.UnexpectedException: Apex triggers can't reference external objects or call out to external data sources.

I went through the below question, but it does not have a solution.

External Object Query in trigger

  • Have you tried moving the logic t o asynchronous context? What do you need the data for?
    – Adrian Larson
    Mar 10, 2020 at 21:04

1 Answer 1


As the error states, querying an External Object means you need a callout. Callouts are not allowed in a DML operation. You need to either query before making your first DML operation, or you need to use asynchronous code (future, batchable, queueable, schedulable) to query the object. What you're trying to do is not directly possible.

  • I think you put a wrong word in your last sentence "doing to do".
    – Adrian Larson
    Mar 10, 2020 at 21:35
  • 1
    @AdrianLarson Haha, yeah, it's been a long day.
    – sfdcfox
    Mar 10, 2020 at 21:40
  • @sfdcfox, as I need to do the query from a trigger, there is no way to perform it before the dml operation. Thanks for your help. I will try the alternatives that you suggested.
    – Madhurima
    Mar 11, 2020 at 10:00

You must log in to answer this question.

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