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

Error : Cannot modify managed object (insert into FieldPermissions for packaged permission set)

Hello everyone,

We have developed an application which will be packaged as an AppExchange solution in the near future. The package includes a permission set for which FieldPermissions for contact custom fields are created dynamically in Apex via a Visualforce page. This Visualforce page will be accessed by a system administrator profile.
When testing the Visualforce page in the developer environment, the field permissions are created successfully.
But when testing a beta version of the managed package in a target Salesforce environment, we are having the following error :

Insert failed. First exception on row 0; first error: CANNOT_MODIFY_MANAGED_OBJECT, Cannot modify managed object: entity=FieldPermissions, component=null, state=MANAGED_INSTALLED: []

The permission set is successfully installed in the target Salesforce org, but it seems that since the system administrator is not allowed to modify this managed component it neither allows to insert into FieldPermissions for this permission set.

No similar issue was found in salesforce developer forum

Does anyone know of a workaround to allow inserting into FieldPermissions for a permission set part of the managed package ?

Any help would be highly appreciated

Best Regards,
In case someone else encounters a similar issue, here is the workaround :

1. do not package the permission set in the managed package (remove it as a component of the package)
2. create the permission set dynamically via apex code
3. then insert into FieldPermissions for this permission set. 

when the managed package will run in the target salesforce org, the permission set will be created via apex code in this org and will allow insert into FieldPermssions for this permission set