Migrate

Updating to the Second-Generation Managed Package

The primary blocker when switching between generations of the Managed Package is managing the access that users have to GRAX features and components. The first-generation package includes legacy permission sets that can be used to control user access, but the second-generation relies on permission sets created by the GRAX application during Auto Config. When removing the first-generation package, users assigned the legacy permission sets need to be updated to the equivalent set to avoid interruptions.

For more details on GRAX's permissions model, see our Permissions documentation.

For migration purposes, the non-defunct legacy permission sets map as follows:

Old Permission Set Name
New Permission Set Name

GRAX Configuration Admin

GRAX Console Admin Permission

GRAX Advanced User

GRAX Console Power Permission

GRAX User

GRAX Console Standard Permission

All other legacy permission sets have no equivalent and are defunct. They can be dropped from users without consequence.

Automatically Migrating Permission Sets

The following steps and script can be used to automatically perform the mapping shown above for all users in your org.

1

Open the Developer Console

Documentation on how to open the console is available here.

Once the console is open, expand the "Debug" menu and click "Open Execute Anonymous Window."

2

Run the Script

Copy the following script into the "Enter Apex Code" dialog box.

private class GRAXLegacyPerm {
  Map<String, Id> psIDs;
  Map<String, Set<Id>> existingConsole;

  public GRAXLegacyPerm() {
    List<PermissionSet>lps=[
        SELECT Id, Name
        FROM PermissionSet
        WHERE name in ('GRAX_Configuration_Admin', 'GRAX_Advanced_User', 'GRAX_User', 'GRAX_Console_Admin_User', 'GRAX_Console_Power_User', 'GRAX_Console_Standard_User')
    ];

    psIDs = new Map<String, Id>();
    for(PermissionSet ps : lps){
        System.debug('PermissionSet '+ps.Name +' Id: ' + ps.Id);
        psIDs.put(ps.Name, ps.Id);
    }

    existingConsole = new Map<String, Set<Id>>();
    for (String name : new String[]{'GRAX_Console_Admin_User', 'GRAX_Console_Power_User', 'GRAX_Console_Standard_User'}) {
         List<PermissionSetAssignment> ecpsa = [
            SELECT AssigneeId
            FROM PermissionSetAssignment
            WHERE IsActive=true
              AND PermissionSetId = :psIDs.get(name)
        ];

        Set<Id> ecpsuID = new Set<Id>();

        for (PermissionSetAssignment a : ecpsa) {
            ecpsuID.add(a.AssigneeId);
        }
        existingConsole.put(name, ecpsuID);
        System.debug('Existing '+name +' User Ids: ' + ecpsa);

    }
  }

  public String migratePermSet(String oldPS, String newPS) {
    List<PermissionSetAssignment> migratePS  = new List<PermissionSetAssignment>();
    List<PermissionSetAssignment> lpsuID = [
        SELECT AssigneeId
        FROM PermissionSetAssignment
        WHERE IsActive=true
          AND PermissionSetId = :psIDs.get(oldPS)
          AND AssigneeId NOT IN :existingConsole.get(newPS)
    ];

    for(PermissionSetAssignment a : lpsuID){
        System.debug('Migrate '+oldPS+' User: ' + a.AssigneeId + ' to '+newPS);

        migratePS.add( new PermissionSetAssignment (
            PermissionSetId = psIDs.get(newPS),
            AssigneeId =  a.AssigneeId
        ));

        if( migratePS.size() > 200) {
            upsert migratePS;
            migratePS.clear();
        }
    }
    if( migratePS.size() > 0) {
        try {
            insert migratePS;
        } catch(DmlException e) {
            System.debug('error: ' + e);
        }
      migratePS.clear();

    }
    return 'done';
  }
}


GRAXLegacyPerm glp = new GRAXLegacyPerm();

glp.migratePermSet('GRAX_Configuration_Admin', 'GRAX_Console_Admin_User');
glp.migratePermSet('GRAX_Advanced_User', 'GRAX_Console_Power_User');
glp.migratePermSet('GRAX_User', 'GRAX_Console_Standard_User');

Click "Execute."

Last updated

Was this helpful?