I'm trying to write custom logs using Platform events into a custom object before API Callout hoping that Platform events would work and will not cause the uncommitted DML before the API Callout. However, I see still the API callout fails due to uncommitted DML transactions.

Is there a way to write custom logs before API callout? I'm also considering big objects if that would help instead of writing the logs into custom SObjects.

  • Did you set the Platform event to trigger immediately? If not, that would cause the DML operation error. I think it should work otherwise?
    – sfdcfox
    Commented Oct 25, 2019 at 3:27
  • Why do you need to write the log before?
    – Adrian Larson
    Commented Oct 25, 2019 at 3:38
  • @sfdcfox - I face the issue even with publish after commit and without any writing any record in the trigger. Commented Oct 25, 2019 at 15:40
  • @AdrianLarson - one use case would be, adding some info / debug logs as I collect data to make an API call. I understand that the other way to handle it is wait for the API call to be done, hold my data and log it after the API call is done. That's my last option if logging with platform events doesn't work before the API call. Commented Oct 25, 2019 at 15:40
  • 1
    Yes, that is exactly what you should do. There is no reason you need to log it before. Hence, don't.
    – Adrian Larson
    Commented Oct 25, 2019 at 15:47


You must log in to answer this question.

Browse other questions tagged .