function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vinay SalveVinay Salve 

Bulk Apex Triggers - Account ID field missing error

Hello All,

Request you to pleaes kindly assist me in the Bulk Apex Trigger Trailhead, I have tried the following coding, however no luck in clearing the Trailhead as I get the error message stating - AccountID field missing.

trigger ClosedOpportunityTrigger on Opportunity (after insert) {
    
    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;
        }
}


Thanks
VInay Kumar Salve
Best Answer chosen by Vinay Salve
Vinay SalveVinay Salve
Thanks Raj for your support, it worked

All Answers

Raj VakatiRaj Vakati
Your code is correct .. but when you verify the trailhead challenge salesforce will insert some data like test classes and verify .. 

So what i am thinking here is the error is coming from some other trigger or process builder .. 

Check the debug logs when you verify the challenge 
Deactivate all other triggers and process builder and see
Vinay SalveVinay Salve
Hi Raj, 

Thanks for responding, however I am not able to understand the problem witht the code, now I have a new error which is a s follows, request you to please assist, thanks

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: 1566532941-39676 (1095682150): []

Thanks in advance.
Vinay Kumar Salve


 
Raj VakatiRaj Vakati
Do one think .. Deactivate this process builder "Opportunity Management" 

and verify the challenge ..
Vinay SalveVinay Salve
Thanks Raj for your support, it worked
This was selected as the best answer