[SalesForce] Why OpportunityShare object and UserRecordAccess objects giving different access level

I am not sure why OpportunityShare object and UserRecordAccess objects are giving different access level for a particular record and user combination.

If i run following query on UserRecordAccess object and try to extract HasEditAccess field it return FALSE.

SELECT RecordId, HasEditAccess FROM UserRecordAccess WHERE UserId
='00570000001pGWABA2' AND RecordId ='006Q000000Bt1eMIBR' // Returns false

but

If i run follwoing query on OpportunityShare object it returns Edit access.

select OpportunityAccessLevel from OpportunityShare WHERE
UserOrGroupId ='00570000001pGWABA2' AND OpportunityId
='006Q000000Bt1eMIBR' // Edit

I am not sure why both queries returning different results?

If i have shared an opportunity with some other user using Apex and grant him Edit right then UserRecordAccess object must return True for that particular user and opportunity combination.

Best Answer

I think you're confusing object-level and record-level permissions. Profiles and permission sets determine how a user can interact with an object, such as Leads, Accounts, and Opportunities. Unless you set View All/Modify All for an object that user may or may not have access to individual records.

Sharing rules modify which records a user can see and edit, providing the user's profile allows for such actions. I can share Opportunities with a user, but if that user's profile does not provide at least Read access to Opportunities that user will never see those records.

Update

UserRecordAccess tells you what access the user has to a particular record; this is the culmination of all of the security settings, starting with the user's profile and assigned permission sets and then applying your global security settings and sharing rules.

If a user is not assigned a profile or permission set granting Edit to the object then UserRecordAccess will always be false since the user does not have access to edit that object.

Related Topic