Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the user's CRUD permissions for an object in Salesforce?

According to a requirement, i have to change the owner of an account if the user does not have read access to a third object.

I need a functionality similar to the isAccessible() method of Describe Field Result, but it is only available for the current logged in user.

Is there any other way to check the user's CRUD permissions for an object in Apex code?

like image 253
ntnng Avatar asked May 09 '12 08:05

ntnng


2 Answers

I wrote an article about this on my blog. There is a feature that was just released in version 24.0 of the API (Spring Release) that will let you do just this on a record by record basis for the current user.

Here is the link to that blog entry that goes into details: How to tell if a user has access to a record

like image 150
John De Santiago Avatar answered Sep 25 '22 23:09

John De Santiago


Don't confuse record level access with CRUD - the latter is the ability for a user to Create, Read, Update or Delete an object in general, regardless of sharing rules etc. that might affect the user's access to a particular record.

To check whether a user can create (e.g. Contacts) in general, just use

Schema.sObjectType.Contact.isCreateable()

(returns true or false)

like image 28
Alexander Sascha Kerschhofer Avatar answered Sep 22 '22 23:09

Alexander Sascha Kerschhofer