I want to create 1 permission set for my managed package and in that I need to assign standard Account object permission and its field permission. So here is my query :

  • Can we assign field permission for permission set through post install script
  • Will permission set will be working fine if created through post install script and package is installed through push upgrade.

Here, I am facing issue that every time my permission set permissions are not assigned same. Is there anything that I should take care of.

  • 1
    Is there a reason you're trying to create the permission set programmatically instead of just creating and packaging it? Commented Jan 29, 2016 at 16:09
  • 1
    Actually, I was facing issue when giving permission for standard objects and for custom objects having master detail with standard object. So thats why I decided to do this. Commented Jan 29, 2016 at 16:13

2 Answers 2


I hit the same issue regarding packaging permission sets and standard objects. I use a script that is similar to the answer above, but rather than run it via the post install script, I created a configuration page that the user can access via the configure link on the installed package screen:

enter image description here

The admin user just clicks a button on the VF page which runs the script to create the perm set, and then lets them view the contents of the permission set. This seemed more in line with what the security teams usually want - which is for the user to explicitly know what permission sets they are creating, and who they are being assigned to.

enter image description here


So short answer is yes but you may have to justify this to security team

Here is one i copied shamelessly from one of the gist repo available

public class UnmanagedPermissionSet{
 private static void ensureUnmanagedPermissionSet(){

    PermissionSet ps = null;
        ps = [SELECT Id, Label, (SELECT SObjectType FROM ObjectPerms) FROM PermissionSet WHERE Name = 'EnableEdit'];
    catch(QueryException qe){
        ps = new PermissionSet(Name = 'EnableEdit', Label = 'Enable edit on Standard Objects');
    upsert ps;

    Map<String,ObjectPermissions> oPerms = new Map<String,ObjectPermissions>();
    if(ps.ObjectPerms != null && !ps.ObjectPerms.isEmpty()){
        for(ObjectPermissions oPerm : ps.ObjectPerms){

    ObjectPermissions campaignPerm = oPerms.get('Campaign');
    if(campaignPerm == null){
        campaignPerm = new ObjectPermissions(SObjectType='Campaign', ParentId=ps.Id);

    campaignPerm.PermissionsRead = true;
    campaignPerm.PermissionsCreate = true;
    campaignPerm.PermissionsEdit = true;
    campaignPerm.PermissionsDelete = true;

    ObjectPermissions contactPerm = oPerms.get('Contact');
    if(contactPerm == null){
        contactPerm = new ObjectPermissions(SObjectType='Contact', ParentId=ps.Id);

    contactPerm.PermissionsRead = true;
    contactPerm.PermissionsCreate = true;
    contactPerm.PermissionsEdit = true;
    contactPerm.PermissionsDelete = true;

    upsert oPerms.values();

  • 1
    @Monith - with above script we can give permission for object, but I am facing issue with field permission, can you please check if it is working for fields as well Commented Jan 29, 2016 at 17:22
  • 1
    Field permissions for standard i believe SFDC does not allow but would test this for fields Commented Jan 29, 2016 at 17:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .