I would like to display different elements to a user depending on whether they have write permissions for a certain field, or just read permissions.
Is it possible to detect user permissions for a field simply on a visualforce page?
Thanks
|
I would like to display different elements to a user depending on whether they have write permissions for a certain field, or just read permissions. Is it possible to detect user permissions for a field simply on a visualforce page? Thanks |
|||
|
|
|
You have two options here....
|
|||||||||
|
|
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_fields_describe.htm There are describe field result methods in apex
The above methods may help you to figure the permissions the current user has on the field for Account Number of Account Object. |
||||
|
|
|
The $ObjectType global variable gives access to certain metadata from within formulas, including Visualforce page expressions. As you probably know, all Visualforce expressions must be placed between two curlybracket-exclamation-close:
The syntax for object metadata is: {!$ObjectType.ObjectName.metadataPropertyName} (italics not working in code formatting, so please leave formatting as is) For instance:
For field metadata it is a bit more involved: {!$ObjectType.ObjectName.fields.FieldName.metadataPropertyName} Examples:
This is not a particularly well documented feature in the context of Visualforce, but all derives from the Schema DescribeFieldResult and DescribeSObjectResult classes in Apex, which are well documented in the Apex code developer guide. I don't know which are or aren't surfaced in the $ObjectType global variable. But typically I just play with it to see. If you can only find a method (like isAccessible or getPrecision) drop the "is" or "get" from the method name and you've typically got it. |
|||
|
|