Simon Fell > Its just code > who.type
Thursday, June 05, 2008who.type
Quick Salesforce.com API tip, most of the API requires you to know both the ID of a record, and its type (e.g to update it, or to retrieve its field values). In most cases it pretty easy to get that, but where most people get tripped up is on polymorphic foreign keys (e.g. whoId on task), the trick is to remember the thing at the end of the relationship can tell you its type, so instead of using this query, then being left trying to work out what type the whoId is,
instead use SOQL-R, and use this query, now you will know what type the whoId is without any further shenanigans (like calling describeSObject on everything and matching the keyprefix which is horribly slow way to do it)
select id, whoId from task
The follow on is that it then becomes easy to run queries that find all tasks ascociated with contacts, it's just
select id, who.id, who.Type from task
select id, who.id, who.Type from task where who.Type='Contact'
You can't post a Comment
Sorry i got sick of comment spam, have something to say about one of my posts, post it to your own weblog.