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:
@isTest
public class PlatformEventTest {
@isTest static void test1() {
// Create test event instance
Order_Event__e newsEvent = new Order_Event__e(
Has_Shipped__c = true);
Test.startTest();
// Call method to publish events
Database.SaveResult sr = EventBus.publish(newsEvent);
Test.stopTest();
// 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 ' +
event.Order_Number__c;
tk.OwnerId = UserInfo.getUserId();
tasks.add(tk);
}
// Insert all tasks corresponding to events received.
insert tasks;
}
}
Are you spotting the error? I'm missing it.