Tuesday, August 1, 2017

How To Check The Object Accessibility On Visualforce Page?

How To Check The Object Accessibility On Visualforce Page?
  Ans:
       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 type error, we should ensure that our  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 this way:
{!$ObjectType.objectname.accessible}
In the same way you can check either the current user has the permission to create,update,delete etc. any object with the following methods :
{!$ObjectType.objectname.createable}
{!$ObjectType.objectname.updateable}
{!$ObjectType.objectname.deletable}
Refer the following URL :
http://www.salesforce.com/us/developer/docs/api/Content
/sforce_api_calls_describesobjects_describesobjectresult.htm
I’ll give you a small example :
Suppose you have added a “Delete” button to delete the account records in your VF page,but an user with custom profile did not have permission to delete the account records. So how you hide that button for a particular user in same VF page. You need to use the above method to hide that button

<apex:commandButton value="DELETE" action="{!doDelete}" rendered="{!$ObjectType.account.deletable}"/>



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.