We created an opportunity and expected it to have an associated task, but it didn’t. Make sure your trigger inserts the task into the database

285 views Asked by At

We created an opportunity and expected it to have an associated task, but it didn’t. Make sure your trigger inserts the task into the database

2 3 4 5 6 7 8 9 10 11 12 13 14 15 trigger ClosedOpportunityTrigger on Opportunity (after insert,after update) { List taskListToInsert = new List();

    for(Opportunity opp : [Select Id,StageName from Opportunity 
                              where Id in :Trigger.New AND StageName = 'Closed Won'])
    {
            taskListtoInsert.add(new Task(Subject ='Follow Up Test Task',WhatId = opp.Id));

    }

if(taskListtoInsert.size()>0)
{
    insert taskListtoInsert;
}

}

1

There are 1 answers

0
TomaszOleszko On

Instead this line

 List taskListToInsert = new List();

try this

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

You should also check if you have any process builder activated that may be causing this problem