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
CCCBBBAAACCCBBBAAA 

How do I grant a user read permission on a record from Apex?

I receive an error "TRANSFER_REQUIRES_READ"  if I try to change the OwnerId of a custom object in my unit tests. I have tried setting the role of the user in question (within the unit test) to our "System Administrator" role, but this yields nothing, I still get the same error. I've also attempted to create a UserRecordAccess object in the test with UserId set to this user, HasReadAccess set to `true', and RecordId set to the custom object, but Salesforce rejects this as well, returning an error stating that UserId field is read-only on UserRecordAccess objects.

Prafull G.Prafull G.
To get rid of the "TRANSFER_REQUIRES_READ" error, You have to ensure that the Profile you are using (i.e. custom or standard) have Read access on the object.
i.e. Setup > Administration Setup > Manage Users > Profile >

Check the Object access settings for the User's profile you are using in your test method.

Cheers!