You need to sign in to do that
Don't have an account?
Salesforce for Outlook: WhoId and WhatId NULL in Before and After Task Triggers
Hello all. We have a trigger on the Task object that looks at the WhatId and/or WhoId to update certain fields on the related Account. A user reported an issue to us when adding emails to Account and Contact records. Upon taking a look at the debug logs, the WhatId and WhoId are both NULL in Before and After triggers. However, after the Task record is saved, the WhatId and WhoId are properly set. The logic of the trigger does not execute properly since the values are NULL when the trigger is executing. Even if I perform a query in the After trigger for the WhatId and WhoId, they are still NULL.
How does Salesforce for Outlook work regarding the WhatId and WhoId?
System.debug commands:
for (Task record : Trigger.new) { System.debug(record.WhoId); System.debug(record.WhatId); System.debug(record.Status); System.debug([SELECT Id, WhoId FROM Task WHERE Id = :record.Id].WhoId);
Result in debug log:
15:26:09.682 (682782000)|USER_DEBUG|[13]|DEBUG|null 15:26:09.682 (682788000)|SYSTEM_METHOD_EXIT|[13]|System.debug(ANY) 15:26:09.682 (682839000)|SYSTEM_METHOD_ENTRY|[14]|System.debug(ANY) 15:26:09.682 (682850000)|USER_DEBUG|[14]|DEBUG|null 15:26:09.682 (682856000)|SYSTEM_METHOD_EXIT|[14]|System.debug(ANY) 15:26:09.682 (682940000)|SYSTEM_METHOD_ENTRY|[15]|System.debug(ANY) 15:26:09.682 (682953000)|USER_DEBUG|[15]|DEBUG|Completed 15:26:09.682 (682959000)|SYSTEM_METHOD_EXIT|[15]|System.debug(ANY) 15:26:09.683 (683169000)|SOQL_EXECUTE_BEGIN|[16]|Aggregations:0|select Id, WhoId from Task where Id = :tmpVar1 15:26:09.700 (700279000)|SOQL_EXECUTE_END|[16]|Rows:1 15:26:09.700 (700390000)|SYSTEM_METHOD_ENTRY|[16]|System.debug(ANY) 15:26:09.700 (700398000)|USER_DEBUG|[16]|DEBUG|null
Hi Eric,
Salesforce for Outlook currently doesn't populate the Related to:(whoID and WhatID) for Tasks and events when syncing from Outlook to Salesforce.
Which is the reason we have the unresolved items where the salesforce user has to manually associate the Task/Event with a particular Account or Contact.
There are some enhancements coming in specific to Event Association in Salesforce for Outlook which you can check in the release notes: page 86:
https://help.salesforce.com/help/pdfs/en/salesforce_winter14_release_notes.pdf
Thanks for the reply Sonam. The part I want to understand is why the tasks do not end up in the Unresolved Items. The tasks are created properly linked with the WhatId and WhoId automatically associated with it. At what point does the WhatId and WhoId get assigned? The CreatedDate and LastModifiedDate fields are identical, so I would expect that an After trigger would be able to select the WhatId and WhoId.
Hi Eric,
We're having the same issue. We have a trigger which checks if the WhoId is populated however the field is always NULL when synced/created from Outlook, even after update.
Did you manage to find a solution?
Thanks,
Ben
Hello Ben,
The workaround I implemented was to have the trigger check to see if WhoId and WhatId were both NULL. If so, the trigger would pass the task Ids to an @future method that would then check to see if WhoId or WhatId was populated.
Let me know if I was not clear in the explanation.
Thanks,
Eric
It works perfectly - thanks a lot Eric!!
I completely forgot I was following this thread, but I saw Dhananjay's question and felt it's a good time to weigh in considering the experience I recently went through.
Our use case was that we wanted to do additional updates whenever a user logs a task, either via Salesforce for Outlook or manually. If the task is logged manually, the WhoId and WhatId are immediately available. If the task is logged via Salesforce for Outlook, this is the tricky part. At one point, yes, I did try Ben's suggestion where you write the trigger to look for tasks coming in where both the WhoId and WhatId were blank and queue this up for an @future method for later processing. It worked for a time and then it stopped.
After a very lengthy discussion and case that was opened with Salesforce support, this solution is not viable. Why? The @future method is asynchronous.
When SFO creates a task, it does it in several stages. It creates the base of the task and then later comes in with another DML to update the task with the Who and WhatIds. The problem with the @future method, is often it can start before the the 2nd DML comes in from the first process and updates the task with the Who and WhatId. You're left with zero results and a broken process and a pretty frustrated developer (hi!).
The best solution we were able to come up with, is to set up a batch process that runs every 5 minutes on all new tasks that have come in (with a 1 minute offset so the ones that came in right before the task kicked off have sufficient time to populate the WhoId and WhatId). In my case, I set up some workflow rules on the task to mark them with a date/time stamp of when the task was officially closed so I had something that was more reliable than the last modified date and a checkbox to queue an item up. Yes, I had to log a case with SF support to convert the checkbox into an indexed field so that my query in the batch class was selective. Another caveat to this - workflow rules do not run on tasks that are associated with emails (such as using 'send an email' on the case). You'll need to write apex code to address those and mimic the behavior of a workflow rule if it's important to you.
Here are my code samples for those who find themselves in a similar boat. Hope this helps,
Kelly
Batch:
Apex Class:
https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=OPENQUESTIONS&id=906F0000000DEuXIAW
In my requirement I have created a WF to update the field on the task. whenever the task is created.In my case when I add an email from outlook to SFDC,it creates a task on contact under Activity History but when i drilldown on it the Field value that i want to populate is display as blank because WF rule is not triggering in case of outlook..
u can check my question which is kinda similar to ur requirement.
and thanks for providing the coding sample...