I am writing code to dynamically assign permissionset and permissionset license to users upon creation time in the user trigger. The scenario is that I want to add an extra permission set to certain user(admin user) to enable them access to 'Product' object. Since accessing to product object is not include in our user license, I am creating an permissionset with 'None' as user license, and before assigning that permission set to users, I need to add 'permissionsetlicense'(Orders Platform) to the users.
I created the trigger, and tested the real time user creation, the permission set license and the correspondent permission set is added correctly. The problem comes when I try to test all these assignment in unit test. During the test, I inserted the permissionset license assignment correctly, however, when the code was trying to insert permissionset assignment I still got DML error:
System.DmlException: Insert failed. First exception on row 1; first error: FIELD_INTEGRITY_EXCEPTION, The user license doesn't allow the permission: Read Product2: []
I wonder why this happened. Is it common practice to test permission set assignment and permission set license assignment in unit test? Since User is an organization level object, and I can see all users in the org within the unit test.
Aucun commentaire:
Enregistrer un commentaire