+ Start a Discussion

Parsing record IDs

What is the best way (if there is one) to send a record ID to a visualforce page and have the page determine the record type?
The ID could represent a contact record, account record, etc.  Do you need to add some javascript to get the DescribeGlobal method and loop thru some metadata and process the ID that way?
Thanks for any info...
Ron HessRon Hess
Is the id of the record for a specific object (concrete) or for any object in the system ( dynamic) ?

if it is concrete, you can just load that record in your controller and look at the recordtype value.

if dynamic, you may have to loop thru the dynamic (describe) calls to get tokens and check until you have a matching record, then query that record.  I've not tried this yet.

Thanks for the response.  The ID is dynamic.  I figured I could grab the first 3 characters of the ID to get the type and then loop thru the metadata to find out what kind of record it is.  Can you reference the Describe calls thru visaulforce or do you have to switch over to javascript and use API calls?
In the Summer '08 release you can access Describe information from apex and thus any visualforce page with a custom controller or extension.
Jon Mountjoy_Jon Mountjoy_
Sorry for newb question here:
Given an incoming Id (which I can retrieve), which may be for any object (and I don't know which, Account, Contact, whatever), how do I retrieve an object so that I can go and fetch the describe information?

ie. I don't know how to start this process given an Id.

It seems like this is more of a question for the Apex Code forums than for the Visualforce forums, since you know how to get the ID from the page.

The documentation for describe (page 100 or so) is pretty helpful:


I am doing the same kind of thing.  With the Summer 08 release, you can use Apex and the Schema.GlobalDescribe method and DescribeSObjectResult to check out info about the ID.   You can use the first 3 characters for the ID to figure out the record type (ie 001 = Account).  The metadata can help match record types.