0

I am doing the trailhead and I am currently at the step: Apex Triggers Bulk

https://trailhead.salesforce.com/trails/force_com_dev_beginner/modules/apex_triggers/units/apex_triggers_bulk

Here is my code for this challenge:

trigger ClosedOpportunityTrigger on Opportunity (before insert, before update) {
    List<Task> taskList = new List<Task>();
        for(Opportunity o : Trigger.new) {
            if(o.StageName == 'Closed Won') {
            Task task = new Task();
            task.Subject = 'Follow Up Test Task';
            task.WhatId = o.Id;
            taskList.add(task);
            }
        }
        insert taskList;
}

Here is the error message I received:

Challenge Not yet complete... here's what's wrong: There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 3011r0000004rvE. Flow error messages: An unhandled fault has occurred in this flow An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []

Here is the log I received:

https://docs.google.com/document/d/1kaaz3BB7qn8H_lepm4suATEdLkMaxu3cOHMyoIoHRok/

  • 1
    Seems like you have a flow created in your org, please review that first also you might need to switch to after trigger as you are creating records of different object. – Mr.Frodo May 21 '18 at 5:45
  • How do I figure out which flow interferes with this trigger? – Flowryn May 21 '18 at 6:32
  • Whichever is working upon opportunity insertion or updation. – Mr.Frodo May 21 '18 at 6:33
  • 2
    I checked your log...Flow Closed_Won_Opportunities_Clone is causing the issue. Deactivate it and try again. Also like I said as you are inserting other object records you should move your logic to after trigger. – Mr.Frodo May 21 '18 at 6:46
  • Thank you @Mr.Frodo. exactly this was the issue, can you please add this to the responses so I can mark as a solution? – Flowryn May 22 '18 at 4:59
1

Pasting from comments:

Checked your log...Flow Closed_Won_Opportunities_Clone is causing the issue.

Deactivate it and try again. Also like I said as you are inserting other object records you should move your logic to after trigger.

Also Trailhead generally suggest to complete challenges in clean org and triggers, validation rules, flows etc need to be checked before submitting challenge as they generally cause some issues.

1

You have to Change the Trigger event to "after Insert" and "after Update" instead of before insert and before Update

trigger ClosedOpportunityTrigger on Opportunity(after insert, after update) {     
   List < Task > taskListToInsert = new List < Task > ();

    for (Opportunity o: Trigger.new) {
      if (o.StageName == 'Closed Won') {
  Task t = new Task();
   t.Subject = 'Follow up Task';
  t.WhatId = o.Id;
  taskListToInsert.add(t); }}

  if (taskListToInsert.size() > 0) {
  insert taskListToInsert;
 }}
  • 1
    The link below does not seem to be related. Also the code seems to be right for this challenge but does not work. – Flowryn May 21 '18 at 6:30
  • 1
    Please check your process builder or flow. It may causes the issue. Use the flow id in url and check whats the root cause. if you deactivate that flow and if you run this trigger.You may complete the challenge. but better way is try to debug it and find the root cause – Annappa PH May 21 '18 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.