My Post-Install Script does not seem to be running as the pages that are being inserted are from a long time ago and only about half of the pages from my module are being inserted. Below is my script and my Module is named UMANO (as state in the script below), and assigned in my managed package.
Any ideas what could be going on here?
public static final String NAMESPACE\_PREFIX = 'UMANO';
public static boolean IsRunning {
public get {
if (IsRunning==null) IsRunning = false;
return IsRunning;
}
public set;
}
public void onInstall(InstallContext ctx) {
IsRunning=true;
RefreshPagesInModule(NAMESPACE\_PREFIX);
IsRunning=false;
}
public static List<skuid __page__ c> RefreshPagesInModule(String module) {
// See if a StaticResource containing new pages for this module yet exists
StaticResource sr = [
select Body
from StaticResource
where Name = :(module + 'Pages')
and ((NamespacePrefix = NULL) OR (NamespacePrefix = :module))
limit 1
];
// The new Pages for our module that we will be inserting
List<skuid __page__ c> newPages
= (List<skuid __page__ c>) JSON.deserialize(sr.Body.toString(),List<skuid __page__ c>.class);
List<schema.sobjectfield> layoutFields = new List<schema.sobjectfield>{
skuid __Page__ c.skuid __Layout__ c,
skuid __Page__ c.skuid __Layout2__ c,
skuid __Page__ c.skuid __Layout3__ c,
skuid __Page__ c.skuid __Layout4__ c,
skuid __Page__ c.skuid __Layout5__ c
};
for (skuid __Page__ c p : newPages) {
// Get rid of the Ids so that upsert will proceed
p.Id = null;
// Ensure that unused Layout fields are set to null
for (Schema.Sobjectfield f : layoutFields) {
if (p.get(f)==null) p.put(f,null);
}
}
// If we have successfully compiled new Pages for this module,
// delete the old ones and replace them with the new.
if (newPages != null && !newPages.isEmpty()) {
Schema.SObjectField f = skuid __Page__ c.skuid __UniqueId__ c;
List<database.upsertresult> cr = Database.upsert(newPages,f,false);
}
return newPages;
}
}
</database.upsertresult></schema.sobjectfield></schema.sobjectfield></skuid page c></skuid page c></skuid page c></skuid page c>