• Nitin Kumar Sharma
  • 0 Points
  • Member since 2020

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 3
Hi All,

iam new to Salesforce and trying to complete the Trail haed challenge for "Build criteria and actions to replace your workflow rules" 
and not able to see the creation of 'task' for the below highligted part in the AddAction.
Criteria 1:
Name: Closed Won and Banking
Conditions: Checks whether the opportunity's Stage is Closed Won AND whether the associated account's Industry is Banking
Associated action: Creates a task for the account owner to follow up on the account. For the due date, use this formula: TODAY() + 7. You can delete the Priority and Status fields.

Can someone help me what option i choose User-added image
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 ?
public class ContactAndLeadSearch {
public static List<List<SObject>> searchContactsAndLeads(string FN)
    List<List<sObject>> searchList = [FIND 'FN' IN all fields 
RETURNING Contact(FirstName,LastName) ,Lead(FirstName,Lastname)];
//Contact[] searchContacts = (Contact[])searchList[0];
//Lead[] searchLeads = (Lead[])searchList[1];
return searchList;


Please someone correct this code ,, this one was nt fulfilling the challenge req.