31

As per Enterprise Messaging Platform in the Summer '17 release notes and First Impressions with Platform Events and the Salesforce Enterprise Messaging Platform I created a simple Platform Event with the API name TestEvent__e and a corresponding trigger.

trigger TestEventTrigger on TestEvent__e (after insert) {
    System.debug('Event Log');

    for (TestEvent__e event : Trigger.New) {
        System.debug('Event: ' + event);
    }
}

Then I ran the following anonymous Apex in the Developer Console:

TestEvent__e testEvent = new TestEvent__e();
List<TestEvent__e> toPublish = new List<TestEvent__e>();
toPublish.add(testEvent);
EventBus.publish(toPublish);

The Developer Console showed the logging for the anonymous apex, but nothing appeared for the trigger subscription to the event.

How do I see debug logging for Platform Event triggers?

2
  • 3
    Nice Q&A, Daniel!
    – sfdcfox
    Commented May 5, 2017 at 1:51
  • 6
    @sfdcfox Thanks. In addition to helping others I hope this will assist "Future Daniel" when I wonder why I'm not seeing the expected debug logs. Commented May 5, 2017 at 1:56

1 Answer 1

41

From Christopher Marzilli via twitter:

when you go into setup to create a new trace you should see an option for "Traced Entity Type" select Automated Process.

It appears that Summer '17 has added a new type of TraceFlag.

enter image description here

To get them to appear in the Developer Console you will also need to uncheck "Show My Current Logs Only" under "Debug" menu in Dev Console. Additionally, it appears that the Streaming API channel that the Developer Console users to monitor for new debug logs won't pickup on the Platform Event Trigger events (or at least it didn't do so consistently for me). So you may need to trigger another log to get it to appear.

From the Platform Events Developer Guide

Debug logs for platform event triggers are created by a process called “Automated Process” and are separate from their corresponding Apex code logs. The debug logs aren’t available in the Developer Console’s Log tab. One exception is Apex tests, which include debug logging for event triggers in the same test execution log. To collect platform event trigger logs, add a trace flag entry for the Automated Process entity in Setup.


Not that Spring '21 will allow Platform Event Triggers to run as a configured user other than "Automated Process". So you might need to check the specific PlatformEventSubscriberConfig record.

4
  • 2
    Early candidate for best answer of Q2. :)
    – Adrian Larson
    Commented May 5, 2017 at 13:47
  • Clutch! Its worth noting that these logs only appear in Setup > Debug Logs and not in the Developer Console Logs tab. Commented Oct 30, 2018 at 20:20
  • 4
    @Shane you may need to unchecked "Show My Current Logs Only" as the logs belong to a different user. Commented Oct 30, 2018 at 23:50
  • Oh sweet, then it will be in Dev Console too. Thanks! Commented Oct 31, 2018 at 15:28

You must log in to answer this question.

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