Salesforce Certified Platform Developer II free question 1 / 10 · Domain 1: Advanced Developer Fundamentals
The organization-wide default for Job__c is Public Read Only. To give a recruiter Read access, a developer creates a share row with the following code. Job__Share s = new Job__Share(ParentId = jobId, UserOrGroupId = userId, AccessLevel = 'Read'); Database.SaveResult r = Database.insert(s, false); Which statement about the result is correct?
- Setting AccessLevel to All makes the insert succeed regardless of the organization-wide default
- Because allOrNone is false, the access level is raised to Edit automatically
- The insert fails, because the access level isn't higher than the organization-wide default
- The insert succeeds and the Read access remains as a share row
Show the answer and explanation
Answer: C
Why this is correct
The "Sharing a Record Using Apex" page says the AccessLevel field of a share object (valid values Edit, Read, and All) must be set to an access level that is higher than the organization's default access level for the parent object. A Read share on an object that is already Public Read Only is not higher, so the insert fails. Because the code passes false for the second argument, the failure is returned in the SaveResult instead of being thrown. The page's example method checks for the status code FIELD_FILTER_VALIDATION_EXCEPTION with a message containing AccessLevel, and its comment says the share is not required, so the failure is acceptable.
Why the other options are wrong
"The insert succeeds and the Read access remains as a share row" … The access level has to be higher than the organization's default for the parent object. A Read row on a Public Read Only object is not, so no share row is saved.
"Setting AccessLevel to All makes the insert succeed regardless of the organization-wide default" … The Note on the page says the All access level is an internal value and can't be granted. To give more than Read, use Edit.
"Because allOrNone is false, the access level is raised to Edit automatically" … Passing false as the second argument of Database.insert allows partial processing and returns each outcome in a SaveResult. It doesn't change the AccessLevel value of the share row.
How the page's example handles it
The page's manualShareRead method calls Database.insert(jobShr, false) so that partial processing is allowed if multiple records are passed in, then reads the first error from the SaveResult. It returns true for the trivial access level error and false for any other failure. The page also warns that the object's organization-wide default access level must not be set to the most permissive level, which is Public Read/Write for custom objects.