contents
Documentation Version
Summer '15 (API version 34.0)
Language
English
  • Winter '16 Preview (API version 35.0) 35.0
  • Summer '15 (API version 34.0) 34.0
  • Spring '15 (API version 33.0) 33.0
  • Winter '15 (API version 32.0) 32.0
  • Summer '14 (API version 31.0) 31.0
  • Spring '14 (API version 30.0) 30.0
  • Winter '14 (API version 29.0) 29.0
  • English
  • Japanese

Checking for Object Accessibility

If a user has insufficient privileges to view an object, any Visualforce page that uses a controller to render that object will be inaccessible. To avoid this error, you should ensure that your Visualforce components will only render if a user has access to the object associated with the controller.

You can check for the accessibility of an object like this:
{!$ObjectType.objectname.accessible}
This expression returns a true or false value.
For example, to check if you have access to the standard Lead object, use the following code:
{!$ObjectType.Lead.accessible}
For custom objects, the code is similar:
{!$ObjectType.MyCustomObject__c.accessible}
where MyCustomObject__c is the name of your custom object.
To ensure that a portion of your page will display only if a user has access to an object, use the render attribute on a component. For example, to display a page block if a user has access to the Lead object, you would do the following:
<apex:page standardController="Lead">
	<apex:pageBlock rendered="{!$ObjectType.Lead.accessible}">
		<p>This text will display if you can see the Lead object.</p>
	</apex:pageBlock>
</apex:page>
It is good practice to provide an alternative message if a user cannot access an object. For example:
<apex:page standardController="Lead">
	<apex:pageBlock rendered="{!$ObjectType.Lead.accessible}">
		<p>This text will display if you can see the Lead object.</p>
	</apex:pageBlock>
	<apex:pageBlock rendered="NOT({!$ObjectType.Lead.accessible})">
		<p>Sorry, but you cannot see the data because you do not have access to the Lead object.</p>
	</apex:pageBlock>
</apex:page>