0

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

1 Answer 1

-1

Yes you can achieve this by using below approach : -

  1. 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.

  2. for each and every object the access level was defined in that share object for respective user.

  3. 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.

4
  • is there any problem in the answer.??
    – Avijit Das
    Commented Apr 7, 2017 at 7:40
  • How is this object created? I queried this object in my org and do not have any associated data.
    – Brian
    Commented 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"
    – Avijit Das
    Commented Apr 7, 2017 at 9:29
  • then no user has access on that record, there should be one record for owner also.
    – Avijit Das
    Commented Apr 7, 2017 at 11:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .