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

Trigger to determine Task WhoId Owner (Best Method?)

I'm working on a trigger that would pull in the owner's name from the owner of a lead/contact associated with a task (aka: whoId).


I'm planning on using this to compare users that are logging tasks for any leads or contacts that actually don't belong to them.


Task > WhoId > Owner > First Name & Last Name


How do I retrieve the owner? Do I have to conditionally determine if the WhoId refers to a contact or lead before attempting to grab the owner id? Or can I use a more general method?

Best Answer chosen by Admin (Salesforce Developers) 

After some searching, I discovered that there is already a much easier method for running reports on this information.


I created a custom report type to display Contacts that had Activities related to them.


Then, I created a report grouped by the Activity Owner, showing the Contact Owner in the details. 


This allows me to see who is logging Activities for Contacts that do not belong to them.


So, this isn't really a developerforce question anymore I guess. No apex necessary!