Getting Object type of WhatId/Who Id Task/Event fields
03-15-2004 11:46 AM
I'm looking to find the object types of the WhatId/WhoId fields of the Task and Event objects, so I can query these objects and get more information about them and perform certain automated tasks based on the type.
I found this tech article, which uses the first 3 digits as a marker, but the article also says that this may change at any time:
http://www.sforce.com/us/resources/tn-1.jsp
Is there a better way of getting the object types of WhatId/WhoId fields or querying them based on Id only (no type)?
Thanks!
I found this tech article, which uses the first 3 digits as a marker, but the article also says that this may change at any time:
http://www.sforce.com/us/resources/tn-1.jsp
Is there a better way of getting the object types of WhatId/WhoId fields or querying them based on Id only (no type)?
Thanks!
Re: Getting Object type of WhatId/Who Id Task/Event fields
12-16-2008 01:33 AM
Well i found something a User poited out on ideas, HE SAID:
"[Select Who.name from task where id = :taskid];
Polymorphic relationships like who and what on task/event or owner on queue-ownable objects can be traversed. The object that is returned is called "Name". Here's the information you can access through this traversal:
(from the enterprise WSDL)
Alias
FirstName
LastName
Name
Type
UserRole
UserRoleId
"
But i could not understand how I could read these columns in APEX class?
My query is like this:
Select Subject,WhoId,WhatId,Who.FirstName,Who.Name,Who.ty pe,What.type From task
Now i get a Collection NAME here which contains (FirstName,Name,Type), but how I could read these Values in APEX class? Any idea ?
"[Select Who.name from task where id = :taskid];
Polymorphic relationships like who and what on task/event or owner on queue-ownable objects can be traversed. The object that is returned is called "Name". Here's the information you can access through this traversal:
(from the enterprise WSDL)
Alias
FirstName
LastName
Name
Type
UserRole
UserRoleId
"
But i could not understand how I could read these columns in APEX class?
My query is like this:
Select Subject,WhoId,WhatId,Who.FirstName,Who.Name,Who.ty
Now i get a Collection NAME here which contains (FirstName,Name,Type), but how I could read these Values in APEX class? Any idea ?
Re: Getting Object type of WhatId/Who Id Task/Event fields
08-29-2011 04:17 PM
oh thanks, i ended up doing what another user posted and it worked!
if(ta.WhatId != null){
String account_prefix = Schema.SObjectType.Account.getKeyPrefix();
String task_whatid = ta.WhatId;
System.debug('who: ' + ta.WhoId + ' what: ' + ta.WhatId + ' prefix: ' + account_prefix + ' eval: ' + task_whatid.startsWith(account_prefix) + ' id: ' + ta.id );
if(task_whatid.startsWith(account_prefix)){
