function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tushmattushmat 

Linking Tasks to Accounts - when using Apex triggers

Hi,

 

I am trying to create a task on creation of an account in a specific industry.

 

When I try to link the account and Task by putting the account id in the WhoID field of the task, I get a exception when the trigger fires.

 

CreateTaskWhenAccountCreated: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Contact/Lead ID: id value of incorrect type: 0014000000NKcUBAA1: [WhoId]

Trigger.CreateTaskWhenAccountCreated: line 46, column 1

 

How do I link a task to an Account differently to avoid getting this exception?

 

Thanks!!

the0nly0nethe0nly0ne
Try putting the Account into the WhatId instead. WhoId is only for Leads and Contacts. I hope this helps.