function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Salesforce DreamerSalesforce Dreamer 

Can my apex code inside a managed package make changes to permission set which is also inside the package?

Hi experts,
I am curious to know if you have come across the below scenario in your implementation.
I have a managed release package (PKG-A) which has the below items:
  1. LEX Component - A
  2. Apex Class - A
  3. Permission set - XYZ [0PS31000000Np44] (Account sObject read access => true)
I install PKG-A in Production org and perform the below operation:
My above LEX component - A has a button that calls the Apex class - A (AuraEnabled method) which runs the below to modify Permission set - XYZ create access to true:
String parameterValue = '0PS31000000Np44'; 
PermissionSet ps =[select id,ProfileId,SystemModstamp,UserLicenseId FROM PermissionSet where id=: parameterValue]; 
ObjectPermissions op = new ObjectPermissions(); 
op.parentid = ps.id; 
op.SobjectType = 'Account'; 
op.PermissionsCreate = true; 
op.PermissionsRead = true; 
op.PermissionsEdit = false; 
insert op;

Now, my question is will the above functionality work?
Thanks for all your support in advance.