0

We are trying to move a task from one contact to another in a trigger. The Task is created by ListEmail functionality.

We are getting an exception when re-assigning the WhoId.

Exception: Update failed. First exception on row 0 with id 00T1N00002TXv3jUAD; first error: FIELD_INTEGRITY_EXCEPTION, Related To ID: id value of incorrect type: 0XB1N000000XaCuWAK: [WhatId]

This is the sample code:

List<Task> task = [SELECT Id, RecordTypeId, WhoId, WhoCount, WhatCount, Subject, AccountId, TaskSubtype, AccountId__c, EmailListWhatID__c FROM Task where Id ='00T1N00002TXv3jUAD'];
system.debug('task = ' + task);
Task tk = task.get(0);
tk.WhoId = '0031N00001UvZDpQAN';
database.update(tk);

(Pseudo-reparenting via a copy of the Task is similarly problematic. We cannot create a new Task where the WhatId is a ListEmail. We /can/ reparent the Task if we clear the WhatId, but this is not ideal.)

  • Does 0031N00001UvZDpQAN represent a Lead/Contact? Also could you confirm if you have Shared Activities enabled? – Jayant Das May 1 '18 at 17:00
  • 2
    Don't ask duplicate questions. And definitely don't create multiple accounts to continue asking questions if you fail to receive the response you want. Sometimes an answer takes time. – battery.cord May 1 '18 at 17:12
  • This isn't a duplicate question (from me), nor did I find a match, and I have only one account. Can you please explain your comment? – A. Miller May 1 '18 at 17:18
  • Jayant, it's a Contact and yes, Shared Activities are enabled. – A. Miller May 1 '18 at 17:20
  • 2
    There was exactly same question posted earlier (which has later taken off). @battery.cord - the other one (with the link you had) was posted after this one, so that was more of duplicate (and that's what I had commented there referring back to this post). However I see now that (duplicate) one is deleted. – Jayant Das May 1 '18 at 17:26
2

Based on the information you provided:

Shared Activities are enabled

You will not be able to update WhoId in that case. This is what the below excerpt from the documentation on WhoId says:

If Shared Activities is enabled, the value of this field is the ID of the related lead or primary contact. If you add, update, or remove the WhoId field, you might encounter problems with triggers, workflows, and data validation rules that are associated with the record.

Additionally, refer to this link where it lists down which fields are not updateable in before or after trigger and mentions about Task.WhoId

Fields Not Updateable in Before Triggers

Task.WhoId (when Shared Activities is enabled)

Fields Not Updateable in After Triggers

The following fields can’t be updated by after insert or after update triggers.

  • Event.WhoId
  • Task.WhoId
| improve this answer | |
  • We update the WhoId on shared tasks during our custom merge process, and we handle TaskRelation records separately by copying and deleting. This error message and behavior seems specific to a ListEmail being the WhatId. As stated above, if we delete the What reference, we can reparent to another contact. – A. Miller May 1 '18 at 17:36
  • That's interesting considering that you cannot update a WhoId at all, if Shared Activities are enabled (per documentation). Can you update your original post, as what works vs. what not, that will help with a perspective to understand in detail. – Jayant Das May 1 '18 at 18:27
-1

As per documentation, Task.WhoId (when Shared Activities is enabled) is not updateable in Before Trigger. I believe it is updateable in After trigger if shared activities are enabled.

If we query a task in anonymous window which has a WhoId (ContactId) and WhatId(ListEmailId) and update it. It gives the same error but if we set the whatId=null then it updates successfully.

Below code works: but we are loosing the relation to ListEmail in task relation.

List<Task> task = [SELECT Id, RecordTypeId, WhoId, WhatId, WhoCount, WhatCount, Subject, AccountId, TaskSubtype, AccountId__c, EmailListWhatID__c FROM Task where Id ='00T1N00002TXv3jUAD'];
system.debug('task = ' + task);
Task tk = task.get(0);
tk.WhoId = '0031N00001UvZDpQAN';
tk.WhatId = null;
database.update(tk);
| improve this answer | |
  • 3
    What you are doing here in anonymous window is not really part of trigger. Have you been able to update WhoId in after trigger? Per documentation you cannot update it in after triggers irrespective of shared activities are enabled or not. – Jayant Das May 1 '18 at 18:53
  • I am able to update the whoId in task (NON ListEmail), though the code is in a queuable class which is queued by the after trigger. I pasted the same code in anonymous window to execute but it failed there also unless I set the whatId to null. – shzad May 1 '18 at 20:15
  • 1
    Remember, once you have anything in queueable (or future method), it's not in the same transaction context. The issue is with updating the WhoId is within the trigger which is a synchronous transaction whereas anything being delegated to queueable or future is asynchronous and not within the same context. – Jayant Das May 1 '18 at 20:45
  • I know that, lets keep aside the trigger and queueable. could you point out the issue in above code if whatId is not set to null and the task is created because of ListEmail? the above code is executed in anonymous window. – shzad May 2 '18 at 16:00
  • Still looking for suggestions.. I need to re-parent the task (Created by ListEmail) from one contact to another. I am not able to do unless i set the whatId to null. If i set the WhatId to null then I am loosing the task relation to ListEmail. – shzad May 10 '18 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.