+ Start a Discussion
r_boyd_848r_boyd_848 

Control button rendering by checking Object level CRUD and FLS rules

So you want to control if something appears on a Visualforce page based on some underlying premission on the object.

 

Everytime I go to use this syntax (but can't remember it exactly) I find it difficult to find in the Salesforce documentation. I don't know way. So I thought I would post it here so it might be easier to find in the future

 

In these examples I'm going to control if a button appears based on the users underlying permission on an object. Lets just say the button opens a Visualforce page that uses myCustomObject__c as its controller.

 

<!-- show if the object accessible to the User -->
<apex:commandButton action=”{!viewRec}” value=”New” rendered=”{!$ObjectType.myCustomObject__c.accessible}” />
<!-- show if user create new record --> <apex:commandButton action=”{!newRec}” value=”New” rendered=”{!$ObjectType.myCustomObject__c.createable}” /> <!-- show if user can edit --> <apex:commandButton action=”{!editRec}” value=”Edit” rendered=”{!$ObjectType.myCustomObject__c.updateable}” /> <!--show if user can delete--> <apex:commandButton action=”{!delRec}” value=”Delete” rendered=”{!$ObjectType.myCustomObject__c.deletable}” />

 You can use this on any VF mark up that supports the rendered attribute. It also works with disabled as well, although I found this not t be the case if the button was being used in a table.

 

Any way this should be easier to find