+ Start a Discussion
dev_forcedev_force 

Passing $ObjectType.Account to visualforce controller via custom button

I use the following link for a custom button: /apex/apexPage?type={!$ObjectType.Account}

 

Which is essentially equivalent to: /apex/apexPage?type=001

 

 

In my visualforce controller i'd like to compare "001" without hard coding a value.  For example, using: "Account.sObjectType" results in "Account" NOT "001".

 

Is there anything equalivent to "$ObjectType.Account" in Apex ? 

 

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber
Yes, see the dynamic Apex chapter in the Apex language reference and/or search for Schema.SObjectType You'll probably need to do a Schema.getGlobalDescribe() call to compare the prefix with the value on describes.

All Answers

mtbclimbermtbclimber
Yes, see the dynamic Apex chapter in the Apex language reference and/or search for Schema.SObjectType You'll probably need to do a Schema.getGlobalDescribe() call to compare the prefix with the value on describes.
This was selected as the best answer
dev_forcedev_force

Schema.DescribeSObjectResult accountDescribe = Schema.SObjectType.Account; accountDescribe.getKeyPrefix()

 

Yeah ended up using the above.