Which two lines of code will trigger a DML exception when attempting to insert a record with an assigned access level into the database? Universal Containers needs the architect to create Apex-managed sharing for the custom Job object. The sharing settings for the Job object are set to Private. A. ObjectName.AccessLevel = 'Read'; B. ObjectName.AccessLevel = 'Edit'; C. ObjectName.AccessLevel = 'All'; D. ObjectName.AccessLevel = 'None';

Answered on

In Salesforce Apex, when dealing with record sharing, you cannot directly set the 'AccessLevel' to arbitrary values. Access levels must correspond to the predefined sharing access levels that Salesforce allows.

The valid access levels for Apex managed sharing are 'Read' and 'Edit'. On this premise:

A. `ObjectName.AccessLevel = 'Read';` - This line will not trigger a DML exception as 'Read' is a valid sharing access level.

B. `ObjectName.AccessLevel = 'Edit';` - This line will also not trigger a DML exception because 'Edit' is a valid sharing access level.

C. `ObjectName.AccessLevel = 'All';` - This line will trigger a DML exception because 'All' is not a valid sharing access level in Apex managed sharing.

D. `ObjectName.AccessLevel = 'None';` - Likewise, this line will trigger a DML exception as 'None' is not a valid sharing access level in Apex managed sharing.

Therefore, the two lines of code that will trigger a DML exception when attempting to insert a record with an assigned access level into the database are:

C. `ObjectName.AccessLevel = 'All';` D. `ObjectName.AccessLevel = 'None';`

Related Questions