I am not spotting what is causing this ERROR:

Challenge Not yet complete... here's what's wrong:
Publishing an Order_Event__e did not create the associated task successfully.
Please check your trigger and event.

There aren't any identified Problems with my OrderEventTrigger.apxt and the following PlatformEventTest.apxc runs successfully:

public class PlatformEventTest {
    @isTest static void test1() {
        // Create test event instance
        Order_Event__e newsEvent = new Order_Event__e(
             Has_Shipped__c = true);


        // Call method to publish events
        Database.SaveResult sr = EventBus.publish(newsEvent);


        // Perform validation here
        // Check that the task that the trigger created is present.
        List<Task> tasks = [SELECT Id FROM Task];
        // Validate that this task was found.
        // There is only one test task in test context.
        System.assertEquals(1, tasks.size());

Failures 0

Total 1

Overall Code Coverage 100%

OrderEventTrigger 100%

My OrderEventTrigger.apxt file contains the following:

// Trigger for listening to Order events.

trigger OrderEventTrigger on Order_Event__e (after insert) {

            // List to hold all tasks to be created.

   List<Task> tasks = new List<Task>();

            // Iterate through each notification.

    for (Order_Event__e event : Trigger.New) {
        if (event.Has_Shipped__c == true) {

            // Create task for team to follow up on the shipped order.

      Task tk = new Task();
            tk.Priority = 'Medium';
            tk.Status = 'New';
            tk.Subject = 'Follow up on shipped order to ' + 
            tk.OwnerId = UserInfo.getUserId();

            // Insert all tasks corresponding to events received.
    insert tasks;

Are you spotting the error? I'm missing it.


2 Answers 2


I'll let you in on a not so well kept secret. You can often troubleshot the Trailhead challenge validation in a developer org. But shh, don't tell anyone!

It's really as simple as having the developer console open and actively capturing debug logs when the validation occurs.

I reran the validation for this challenge and got the following logs.

enter image description here

So Trailhead ran two lots of anonymous Apex to validate the challenge. Interesting...

If we drill into the first anonymous Apex class we can see exactly what they are doing. Publishing the event for Order # 105.

enter image description here

Order_Event__e orderEvent = new Order_Event__e(Order_Number__c='105', Has_Shipped__c=true);
Database.SaveResult sr = EventBus.publish(orderEvent);

And then that second call to validate that it worked as expected.

enter image description here

List<Task> tasks = [select id from task where subject = 'Follow up on shipped order 105'];
System.assert(tasks.size() > 0);
delete tasks;

Now we know this, there are two things we could do:

  1. Create a Task before running the validation with the subject 'Follow up on shipped order 105'
  2. Further debug your Platform Event to figure out why it isn't meeting those requirements.

While the 1st option may be tempting and easy it doesn't really help you in the long run. What's the point in cheating yourself of the opportunity to learn more in the debugging process.

I'd recommend modifying your Apex test case to replicate the assertions Trailhead is making. You could also look at capturing debug logs for the Platform Events to see what happens when the trigger fires.

For a not so subtle hint. Check your Task subject closely to see if there is anything out of place.

  • 1
    Nice blog post! And nice subtle hint at the end there. :)
    – Adrian Larson
    Aug 24, 2017 at 4:20

Another possible solution if your having an error is to check the field types on your platform event.

IsShipped should be a checkbox field. Order number should be a text field.

I had the "Cannot Publish Event_Order__e Event" error because my Order Number field was a number type instead of text.

  • Thank you SFDCGuestDev - This worked for me. I didn't even have the Order Event Object in the org and had to create it with two fields and changed the field type to text and it worked.
    – Kashi A.
    Oct 15, 2022 at 17:11

You must log in to answer this question.

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