January 20, 2015

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!!!

1 comment:

  1. Use Case Creating visualforce page to conditionally render elements from various custom objects based on the user's permission set assignment. Currently, the visualforce page in use uses the rendered condition based on the user profile. The issue is that all users have the same base profile and that we differentiation application access using permission sets.

    ReplyDelete