function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hyjhyj 

How to check whether a specified object (e.g. Account) is readable/editable for a user?

Hi all,

I've got a SFDC user sandbox and cuold login successfully with SOAP API.
When I get an object name, E.G. Account, how could I have a check whether I could read or edit its records before really having a try to read out a record or modify a record?
Any suggestion is expected.

Thanks
Best Answer chosen by hyj
Łukasz BieniawskiŁukasz Bieniawski
Hi Hyj,

I do not see any other way than querying UserRecordAccess object at this moment.
If you are getting data/working in one user context you can just mark webservice class as 'with sharing' keywords to be sure that only accessible data will be returned, but in this case you do not know whether user can edit or delete a record.

Best Regards,
Lukasz
 

All Answers

Łukasz BieniawskiŁukasz Bieniawski
Hi Hyj,

You can query UserRecordAccess object:
SELECT RecordId, HasReadAccess, HasDeleteAccess, HasEditAccess, HasTransferAccess, MaxAccessLevel
     FROM UserRecordAccess
     WHERE UserId = [single ID]
     AND RecordId = [single ID]      //or Record IN [list of IDs]
You can find more info here (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_userrecordaccess.htm).

Hope this helps,
Lukasz
hyjhyj
Hi Lukasz,

It seems that it is required that the object UserRecordAccess could be accessed first.
Is there any way to get these informations for most (it is best to be all) users?

Thanks
Łukasz BieniawskiŁukasz Bieniawski
Hi Hyj,

I do not see any other way than querying UserRecordAccess object at this moment.
If you are getting data/working in one user context you can just mark webservice class as 'with sharing' keywords to be sure that only accessible data will be returned, but in this case you do not know whether user can edit or delete a record.

Best Regards,
Lukasz
 
This was selected as the best answer
hyjhyj
Thank you very much!