• Mounika Buddabathina
  • NEWBIE
  • 15 Points
  • Member since 2018
  • Salesforce Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 6
    Replies
Hello Community,
 I'm Working on the Bulk Apex Triggers Trailhead and its throwing me the following error.
Question:
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.
Here is my code:
trigger ClosedOpportunityTrigger on Opportunity (after insert,after update) {
    List<task> tasktoInsert = 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';
            tasktoInsert.add(t);
        }
    }
    if(tasktoInsert.size()>0) {
        insert tasktoInsert ;
    }
}

 Error:
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_INSERT_UPDATE_ACTIVATE_ENTITY, ClosedOpportunityTrigger: execution of AfterInsert caused by: System.StringException: Invalid id: opp.Id Trigger.ClosedOpportunityTrigger: line 7, column 1: []

Hope you guys can help me.
Thanks in advance,
Mounika.

i not understanding usage of junction object .

Please explain usage and how to create junction object with a example