• Yamala Hareesh
  • 0 Points
  • Member since 2019
  • Salesforce developer

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 2
I want to send Visualforce Email Template as a pdf to records (parent Account object email field and Invoice object email address) whenever a new child record created --- by trigger or process builder.
For the above qus I wrote the below code : 

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

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

for (opportunity a :[select ID,StageName  from opportunity where StageName='Closed Won' and ID IN :Trigger.New])

t1.add(new Task(subject= 'Follow Up Test Task', WhatId=a.ID));

if(t1.size() >0 && t1.size()<=200)
insert t1;

But getting a error like   :
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, trig_conts_opprty: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0 with id 0032800000QkI6aAAF; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] Trigger.trig_conts_opprty: line 10, column 1: []

Anyone please tell me the possible reason for the error ?