You need to sign in to do that
Don't have an account?

Publishing an Order_Event__e did not create the associated task successfully. Please check your trigger and event
I cannot complete the Subscribe to Platform Events challenge. When I click the 'Check Challenge' button I get the following error:
Publishing an Order_Event__e did not create the associated task successfully. Please check your trigger and event.
Here is my code:
trigger OrderEventTrigger on Order_Event__e (after insert) {
// List to hold all tasks to be created.
List<Task> tasks = new List<Task>();
// Get queue Id for case owner
String usr = UserInfo.getUserId();
// Iterate through each notification.
for (Order_Event__e event : Trigger.New) {
if (event.Has_Shipped__c == true) {
// Create Task to dispatch new team.
Task t = new Task();
t.Priority = 'Medium';
t.Status = 'New';
t.Subject = 'Follow up on shipped order' + event.Order_Number__c;
t.OwnerId = Usr;
tasks.add(t);
}
}
// Insert all tasks corresponding to events received.
insert tasks;
}
Please assist. Thanks.
Publishing an Order_Event__e did not create the associated task successfully. Please check your trigger and event.
Here is my code:
trigger OrderEventTrigger on Order_Event__e (after insert) {
// List to hold all tasks to be created.
List<Task> tasks = new List<Task>();
// Get queue Id for case owner
String usr = UserInfo.getUserId();
// Iterate through each notification.
for (Order_Event__e event : Trigger.New) {
if (event.Has_Shipped__c == true) {
// Create Task to dispatch new team.
Task t = new Task();
t.Priority = 'Medium';
t.Status = 'New';
t.Subject = 'Follow up on shipped order' + event.Order_Number__c;
t.OwnerId = Usr;
tasks.add(t);
}
}
// Insert all tasks corresponding to events received.
insert tasks;
}
Please assist. Thanks.
Sorry for this issue you are encountering.
May I suggest you please refer to the below code which might help you. Hope this helps.
Kindly mark this as solved if it's resolved.
Thanks,
Nagendra
All Answers
Sorry for this issue you are encountering.
May I suggest you please refer to the below code which might help you. Hope this helps.
Kindly mark this as solved if it's resolved.
Thanks,
Nagendra
Hi All,
The above answer will make you pass the challenge but if you want to check what error your code made is . Everything in there in the section and the only line that is wrong is
tcase.Subject = 'Follow up on shipped order'+ event.Order_Number__c;
there should be space after order
tcase.Subject = 'Follow up on shipped order '+ event.Order_Number__c;
And you will pass :) #HappyCoding
Still getting the same error :
Publishing an Order_Event__e did not create the associated task successfully. Please check your trigger and event.
trigger OrderEventTrigger on Order_Event__e (after insert) {
// List to hold all tasks to be created.
List<Task> tasks = new List<Task>();
// Get queue Id for task owner
User q = [Select Id From User Where IsActive = true LIMIT 1];
// Iterate through each notification.
for (Order_Event__e event : Trigger.New) {
if (event.Has_Shipped__c == true) {
// Create task to dispatch new team.
Task ts = new task();
ts.Priority = 'Medium';
ts.Subject = 'Follow-up on shipped order ' +
event.Order_Number__c;
ts.OwnerId = event.CreatedById;
tasks.add(ts);
}
}
I have also tested the code with the following test, which doesn't give me any errors.
@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();
Database.SaveResult sr = EventBus.publish(newsEvent);
Test.stopTest();
System.assertEquals(true, sr.isSuccess());
List<Case> cases = [SELECT Id FROM Case];
// Validate that no cases were found.
System.assertEquals(0, cases.size());
}
}
// Insert all cases corresponding to events received.
insert tasks;
}
Could it be something with the way my events are configured in my org, or is it my code? Any help is much appreciated.
Sincerely,
Graeme
May be this should help. After adding tasks to list you should insert them.
It should be "Follow up" instead of "Follow-up".
trigger OrderEventTrigger on Order_Event__e (after insert) {
// Trigger for listening to Order_Event events.
// List to hold all cases 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 Case to dispatch new team.
Task ts = new Task();
ts.Priority = 'Medium';
ts.Subject = 'Follow up on shipped order ' + event.Order_Number__c;
ts.OwnerId = event.CreatedById;
tasks.add(ts);
}
}
// Insert all cases corresponding to events received.
insert tasks;
}
trigger OrderEventTrigger on Order_Event__e (after insert) {
List<Task> Tasks = new List<Task>();
// Get queue Id for case owner
Group queue = [SELECT Id FROM Group WHERE Name='Regional Dispatch' AND Type='Queue'];
// Iterate through each notification.
for (Order_Event__e event : Trigger.New) {
if (event.Has_Shipped__c == true) {
// Create Case to dispatch new team.
Task tsk = new Task();
tsk.Priority = 'Medium';
tsk.Status = 'New';
tsk.Subject = 'Follow up on shipped order ' + event.Order_Number__c;
tsk.OwnerId = event.CreatedById;
Tasks.add(tsk);
}
}
// Insert all cases corresponding to events received.
insert Tasks;
}
// Trigger for listening to Order_Event__e events.
trigger OrderEventTrigger on Order_Event__e (after insert) {
// List to hold all cases to be created.
List<Task> tasks = new List<Task>();
// Get queue Id for Task owner
User q = [Select Id From User Where IsActive = true LIMIT 1];
// Iterate through each notification.
for (Order_Event__e event : Trigger.New) {
if (event.Has_Shipped__c == true) {
// Create task to dispatch new team.
Task ts = new Task();
ts.Priority = 'Medium';
ts.Status = 'New';
ts.Subject = 'Follow up on shipped order 105';
ts.OwnerId = event.CreatedById;
tasks.add(ts);
}
}
// Insert all tasks corresponding to events received.
insert tasks;
}
a)we have done lot of customization to task object while doing prev trailblazer course so there could be some field required etc
Here is how i solve the problem
a)Use another playground and create order event again but this time with shipped field default as checked (I think their test developer might have bug )
B)copy the above trigger code
c)it orked perfectly well
I think Mahesh was right, because when I set the debug log I found that due to task trigger it was failing to create Task, so make sure to inactivate any task trigger or validation rules or look up filter whatever may be that'swhy its important to set debug log.
Thanks!
Shubhankar