Skip to main content
Create an Apex trigger for Opportunity that adds a task to any opportunity set to 'Closed Won'.

 

To complete this challenge, you need to add a trigger for Opportunity. The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.

 

The Apex trigger must be called 'ClosedOpportunityTrigger'

 

With 'ClosedOpportunityTrigger' active, if an opportunity is inserted or updated with a stage of 'Closed Won', it will have a task created with the subject 'Follow Up Test Task'.

 

To associate the task with the opportunity, fill the 'WhatId' field with the opportunity ID.

 

This challenge specifically tests 200 records in one operation.

 

My code is : 

 

trigger ClosedOpportunityTrigger on Opportunity (after insert,after update) {

 

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

 

    

 

    for(Opportunity opp:Trigger.new)

 

    {

 

        if(opp.StageName == 'Closed Won')

 

        {

 

            Task t = new Task();

 

            t.Subject = 'Follow up Test Task';

 

            t.WhatId = opp.Id;

 

            taskListToInsert.add(t);

 

        

 

        }

 

    }   

 

    if(taskListToInsert.size() > 0)

 

    {

 

        insert taskListToInsert;

 

    }

 

}

 

And I am getting error as below:

 

Challenge not yet complete in My Trailhead Playground 3

 

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, We can't save this record because the “Opportunity Management” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: REQUIRED_FIELD_MISSING: Required fields are missing: [AccountId]. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 1597114253-6774 (1125517023): []

 

What should I do?

 

 
1 respuesta
  1. 25 mar 2020, 04:27

    Hi Sager,

    It is not trigger issue. You have "Opportunity Management" named Process builder. That is trying to call a flow to create records. Try to deactivate process builder if  not needed and then you can run your trigger.

    Hope it will help you.

0/9000