2

I have requirement like in managed package, we have a custom field on Contact Object. We need to grant the edit access to this custom field for all the users who have Create access on the Contact object.

So we have created a Permission set for the same, but identifying correct user & assigning permission set to them manually is time consuming & we want after package installation permissions should be set automatically.

So we have written apex code in Post Install Class of the managed package to assign the permission set to the users using PermissionSetAssignment object.

  PermissionSetAssignment assignmt = new PermissionSetAssignment();
  assignmt.PermissionSetId = permission set id
  assignmt.AssigneeId = user id; 
  insert assignmt;

But when have created a new beta version of managed package & trying to install it on one developer org then showing error as below:

Problem: 1. Insufficient Privileges You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.

0
1

Please try the class with "Without Sharing".

As per one of the thread - InstallHandler runs under ghost user.

See this thread for detailed answer - InstallHandler runs under a special ghost user. What rights does it have?

3
  • Thanks Ysr, but if we used 'without sharing' then this error may not occur but as it's a managed package so in security review they will not allow 'without sharing' for class. Jul 7 at 4:42
  • not necessary. Even if required, we can mention in the false positive.
    – Ysr Shk
    Jul 7 at 4:48
  • okays will check. Thanks Yasar. Jul 7 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.