1

I have below code in my Trigger which is trying to assign a Task to a Queue. I have provided access to Task object to the Queue. Below code works in anonymous window, it works when I create a Task in Anonymous window. However, automated test and apex trigger is giving me below error:

System.DmlException: Update failed. First exception on row 0 with id a0902000000Br9zAAC; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, FinancialAccountTrigger: execution of AfterUpdate
caused by: LoggedException: Error while inserting task id: null Message: Assigned To ID: id value of incorrect type: 00G0f000005n0paEAA

Group accountHoldTaskOwner = [Select id from Group Where DeveloperName = 'Account_Team' AND Type = 'Queue' LIMIT 1]
Task t = new Task();
t.WhatId = account.id;
t.Status = 'Open';
t.Subject = 'Follow up with Customer';
t.Description = 'Follow up with Customer';
t.ActivityDate = Date.today().addDays(2);
t.OwnerId = accountHoldTaskOwner.Id;

Database.insert(t, true);
2
  • what is the version of the trigger/testmethod? Is the running user of the test the same as when you did the execute anonymous?
    – cropredy
    Commented Apr 28, 2021 at 19:19
  • Running user is myself but your comment gave me the clue I needed. The class version needs to be greater than 48 to make it work. Thank you @cropredy you just saved me bunch of hours. Commented Apr 28, 2021 at 20:16

1 Answer 1

2

Change the version of the class to be more than 48. I set to 50 and it worked.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .