2

Suppose I have a profile PA_User and I want to know what kind of permissions(create, edit, view all, modify all etc) this profile has on Account, opportunity, PAUser (custom object) objects using APEX. How can I get this information?

5

You can check the DescribeSObjectResult for a given object to see if the user can read (queryable), create (createable), update (updateable), or delete (deletable). You can't ascertain if the user has View All Data or Modify All Data, however, as this information isn't available in the normal API. There is an app that can describe a profile's extended permissions and cache them for querying within salesforce.com, but I can't seem to find it right now; you'll need to look around for it. Comments or updates to the answer for the link to that app would be appreciated.

  • Actually i have a list of users. Now for all those users i need to check whether they have create, edit permissions on Account, opportunity objects. what would be the best way to do so – Pramod Kumar Sep 12 '13 at 5:34
  • There isn't an easy solution for this, because the Metadata API is the only way to find out this information, and it's not available in Apex Code. You'd have to do this using some metadata analyzer (e.g. Object Metadata Snapshot Tool) or an external service of some sort. – sfdcfox Sep 12 '13 at 19:15
  • This has actually been changed. You can now query via the rest API at /services/data/v35.0/connect/organization and look under the "userSettings" object for modifyalldata and viewalldata. – techbusinessman Dec 9 '15 at 23:29
0

Permission on sObject are retrieved by Apex System Describe Object methods:

for ex: If you have Account sObject then you can check its permission as

//Is user has permission to insert record
Schema.SObjectType.Account.isCreateable(); // return true if has create permission otherwise false

// Same as to check about update permission
Schema.SObjectType.Account.isUpdatable(); // return true if has record update permission otherwise false

Same as you can check for field permissions also as:

if (Schema.sObjectType.Contact.fields.Email.isAccessible()) {
   // If yes then DO SOMETHING here
}

There are so various method provided to check permission you can look here

  • Actually i have a list of users. Now for all those users i need to check whether they have create, edit permissions on Account, opportunity objects. what would be the best way to do so – Pramod Kumar Sep 12 '13 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.