Rendering based on Object access in Salesforce

Rendering based on Object access in Salesforce

$ObjectType.ObjectName.accessible – Check whether the user has access to the object.

$ObjectType.ObjectName.createable – Check whether the user has create access to the object.

$ObjectType.ObjectName.updateable – Check whether the user has update or edit access to the object.

$ObjectType.ObjectName.deletable – Check whether the user has delete access to the object.

Sample Code:

<apex:page >
<apex:form >
    <apex:pageBlock rendered=”{!$ObjectType.Employee__c.accessible}”>
        <!– Code to show components that should be visible only to to users who has access to Employee object –>
    </apex:pageBlock>
    <apex:pageBlock rendered=”{!$ObjectType.Employee__c.createable}”>
        <!– Code to show components that should be visible only to to users who has create access to Employee object –>
    </apex:pageBlock>
    <apex:pageBlock rendered=”{!$ObjectType.Employee__c.updateable}”>
        <!– Code to show components that should be visible only to to users who has update access to Employee object –>
    </apex:pageBlock>
    <apex:pageBlock rendered=”{!$ObjectType.Employee__c.deletable}”>
        <!– Code to show components that should be visible only to to users who has delete access to Employee object –>
    </apex:pageBlock>
</apex:form>
</apex:page>

Cheers!!!

Leave a Reply