Column Preferences Migration Script

This script migrates custom column data from the Planners - Resource, Planners - Project, and Project Task Gantt Settings custom settings into custom sObjects. For details on use, see Configuring Custom Columns with a Custom Object and Migrating Column Preferences from Custom Settings to Custom Objects.

You must have administrator access in your org to use this script.

Migration Script

//PACKAGED VERSION
//Delete any existing records in the sObject before starting the import process
//delete [select id from pse__Column_Preferences__c];

//Repeat this anon apex as needed to migrate All custom settings (4000 records per execution)
list<pse_ColumnPreferences_c> csList =
[SELECT name,pse_Widthc,pseOrderc,pseFieldc,pseVisiblec,pseValue_c
FROM pse_ColumnPreferences_c
LIMIT 4000
];

String prefix = Schema.SObjectType.User.keyPrefix;

Set<Id> userIdsToQuery = new Set<Id>();
for (pse_ColumnPreferences_c cs : csList)

{ userIdsToQuery.add(Id.valueOf(prefix + cs.Name.substring(0,15))); }
Set<Id> activeUserIds = new Map<Id, User>([SELECT Id FROM User WHERE ID in :userIdsToQuery AND IsActive = true]).keySet();

list<pse_ColumnPreferencesc> preferencesToProcess = new List<pseColumnPreferences_c>();

list<pse_Column_Preferencesc> soList = new list<pseColumn_Preferences_c>();

for (pse_ColumnPreferences_c cs : csList)
{
if(activeUserIds.contains(Id.valueOf(prefix + cs.Name.substring(0,15))))

{ pse__Column_Preferences__c so = new pse__Column_Preferences__c(); so.pse__User__c = prefix + cs.Name.substring(0,15); so.pse__Feature__c = cs.Name.substring(15,16); so.pse__Width__c = cs.pse__Width__c; so.pse__Order__c = cs.pse__Order__c; so.pse__Field__c = cs.pse__Field__c; so.pse__Visible__c = cs.pse__Visible__c; so.pse__Value__c = cs.pse__Value__c; soList.add(so); }
else

{ // Not a record for an active user }
}

insert soList;
delete csList;