I would like to change the ownership of multiple records using apex. Before changing the ownership I want to check whether the said user has read/edit access on this object type. This needs to be done for multiple users so I'm looking for an efficient way to query this information. I'm running as a system user. Can this be achieved?
1 Answer
Yes you can achieve this by using below approach : -
For every object salesforce storing the access in the related share object.for example if you are talking about standard object like Account then the share object name will be AccountShare and if it is custom object like customobject__c then the share object name should be customobject__c_Share.
for each and every object the access level was defined in that share object for respective user.
before changing the owner you need to query share object for that custom object like below : -
SELECT AccessLevel,Id,UserOrGroupId FROM customobject__c
AccessLevel options are "Read" and "Edit" and UserOrGroupId options are either user or any group.
after query will be done you can check the access level of that user on the object then you can change the owner of the record.
i think this will solve you purpose.
-
-
How is this object created? I queried this object in my org and do not have any associated data.– BrianCommented Apr 7, 2017 at 9:01
-
This object is created automatically by saleforce, you just need to query on that object. The object name should be "Your object" +"share" Commented Apr 7, 2017 at 9:29
-
then no user has access on that record, there should be one record for owner also. Commented Apr 7, 2017 at 11:12
UserRecordAccess
as mentioned in this answer salesforce.stackexchange.com/a/191/18297