Study for the Salesforce Platform Developer Exam. Study with flashcards and multiple choice questions, each question has hints and explanations. Get ready for your exam!

Practice this question and more.


How would a developer determine if a CustomObject__c record has been manually shared with the current user in Apex?

  1. By querying the role hierarchy.

  2. By calling the isShared() method for the record.

  3. By querying CustomObject__Share.

  4. By calling the profile settings of the current user.

The correct answer is: By querying CustomObject__Share.

To determine if a CustomObject__c record has been manually shared with the current user in Apex, querying the CustomObject__Share table is the appropriate method. In Salesforce, when a record is manually shared, it creates an entry within the corresponding share table for that object. The share table includes entries for explicitly sharing records with specific users or groups. By querying the CustomObject__Share object, the developer can check for any existing share entries for the specified record that include the current user's ID. This approach allows the developer to ascertain whether or not that particular record has been shared with the user in question, based on the entries present in the share table. This method is directly aligned with Salesforce's sharing model, where share records determine the access level for records outside of the standard role hierarchy and default sharing settings. Thus, it provides a reliable way to check for manual sharing specifically.