function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Natalya MurphyNatalya Murphy 

Event trigger doesn't appear to be firing

This is for the "Subscribe to Platform Events" unit in the "Platform Event Basics" module.  I have: ​
- Created the trigger
- Created a test class
- Verified that the trigger is active
- Set up debug logging on my user ID and on Automated Process
- set up tracing on the trigger
- added system.debug messages in the trigger

When I run the apex test, I see no evidence of the trigger getting fired.   Debug Logs also don't show any evidence of trigger firing.  

The ApexTrigger Event Type log in the Salesforce Event Log File Browser does not show the trigger being fired.

What am I missing?  Code for trigger and test is below.
trigger OrderEventTrigger on Order_Event__e (after insert) {
	System.debug('OrderEventTrigger firing');
    List<Task> allTasks = new List<Task>();
    Task newTask = null;
    System.debug('Order count: ' + Trigger.New.size());
    for( Order_Event__e nextOrder : Trigger.New ){
        System.debug('Shipped: ' + nextOrder.Has_Shipped__c);
        if( nextOrder.Has_Shipped__c == true ){
			System.debug( 'Creating task');
            newTask = (new Task(Subject='Follow up on shipped order' + nextOrder.Order_Number__c,
                                 Priority='Medium', Status='New', OwnerId=Userinfo.getUserId()));
            AllTasks.add(newTask);
            System.debug(newTask);
        }//if
    }//for
    
    insert allTasks;
}
 
@isTest
public class OrderEventTriggerTest {
    @isTest static void test1(){
        Order_Event__e orderEvent = new Order_Event__e(Has_Shipped__c=true, 
                                                       Order_Number__c='333');
        
        Test.startTest();
        System.debug('Sending event:' + orderEvent);
        Database.SaveResult sr = EventBus.publish( orderEvent );
        Test.stopTest();
        List<Task> tasks = [SELECT Id from Task];
        System.assertEquals(1, tasks.size());
    }
}

 
Amit Chaudhary 8Amit Chaudhary 8
Please make sure your trigger is Active ? and you are not doing any Insert event in OrderEventTriggerTest  test class for Order_Event__e  object.
@isTest
public class OrderEventTriggerTest {
    @isTest static void test1(){
        Order_Event__e orderEvent = new Order_Event__e(Has_Shipped__c=true, 
                                                       Order_Number__c='333');
        
		
        Test.startTest();
        
		insert 	orderEvent;
		System.debug('Sending event:' + orderEvent);
        
		//Database.SaveResult sr = EventBus.publish( orderEvent );
        
		Test.stopTest();
        
		List<Task> tasks = [SELECT Id from Task];
        System.assertEquals(1, tasks.size());
    }
}



Let us know if this will help you
Natalya MurphyNatalya Murphy
As I wrote in my original post, I have verified that the trigger is active:
User-added image

I wrote the test code based on the sample code in the unit and it runs without issue.  But it doesn't look like the trigger is being fired.
Natalya MurphyNatalya Murphy
I'm not sure why, but the trigger is suddenly working.  I did not make any changes to it.  I did, however, create a second trigger that only logs a debug statement.  Now both triggers are firing.  Still don't know why.
Ryan DRyan D
I did the Electric Imp trailhead and found it to be somewhat inconsistent in terms of the platform events actually entering the Org and subsequently having the trigger running.  In the Electric Imp IDE it show a successful send but there is no log in the dev console and no new 'reading' showing up in salesforce.  I found that by restarting the device, re-logging into salesforce from the device IDE, deleting the custom object records in salesforce, or a combination of these things makes it start working again.  It's hard to troubleshoot when the device says it's successfully sending readings or 'platform events'.