2

I have created a platform event with Publish Immediately behavior. It is very basic one. Once it is published, I want to upsert a custom object records. I am publishing it through developer console and subscribing through trigger (it is active) on after insert. In trigger, I am just printing the Trigger.New list. I can see in the logs, it is getting publish successfully but trigger is not getting invoked. Is there anything that I am doing wrong? Below are the details:

Platform Event:

Platform event

Publishing through Developer Console:

List<Test__e> testvents = new List<Test__e>();
testvents.add(new Test__e(Name__c='Test'));
// Call method to publish events
List<Database.SaveResult> results = EventBus.publish(testvents);

// Inspect publishing result for each event
for (Database.SaveResult sr : results) {
    if (sr.isSuccess()) {
        System.debug('Successfully published event. '+sr);
    } else {
        for(Database.Error err : sr.getErrors()) {
            System.debug('Error returned: ' +
                    err.getStatusCode() +
                    ' - ' +
                    err.getMessage());
    }
}       

Apex Trigger:

enter image description here

Apex Debug:

enter image description here

7
  • you might need to have test coverage of the trigger first; you should also query EventBusSubscriber to verify there are no errors
    – cropredy
    Commented May 26, 2021 at 16:55
  • Hi @cropredy, trigger contains nothing but a system debug statement. Also can you share how would having trigger code coverage help to overcome the issue? Querying EventBusSubscriber returned the subscribing trigger. Commented May 26, 2021 at 17:22
  • Write a test method that does an EventBus.publish.
    – cropredy
    Commented May 26, 2021 at 18:42
  • I did that. The test class executed successfully. Also in debug, the event got published successfully and EventBusSubscriber returned trigger and subscribing process builder records. But still trigger or the apex class I am calling from process builder is not executing. Commented May 27, 2021 at 13:25
  • 1
    Unless configured otherwise, the trigger will run as Automated Process user. Did you look at debug logs for Automated Process user?
    – cropredy
    Commented May 27, 2021 at 14:00

1 Answer 1

4

Unless configured otherwise, the Platform Event trigger will execute in the context of the Automated Process user. Check the debug log for the Automated Process user and you'll see your trigger execute.

You must log in to answer this question.

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