Deploying Child Pages with Post Install Apex Script

Figured this should have its own thread. Continued from here: https://community.skuidify.com/skuid/topics/appexchange-package-upload-to-include-custom-themes
Child pages do not update at all via the post install script and are untouched. Manually I can unpack the pages from the static resource.
I am unable to figure out how to get my post install script to auto deploy my child pages. I imagine this has to do with every org having different Ids for pages. The script would need to identify master pages, deploy those first, identify child pages, and link those back to the already deployed master pages.
Child pages do not update at all via the post install script and are untouched. Manually I can unpack the pages from the static resource.
I am unable to figure out how to get my post install script to auto deploy my child pages. I imagine this has to do with every org having different Ids for pages. The script would need to identify master pages, deploy those first, identify child pages, and link those back to the already deployed master pages.
1
Categories
- 7.9K Questions
- 926 Ideas
- 220 Discussion Categories
- 178 General
- 9 Community Feedback
- 3 Community Info
- 18 Knowledge Base
Comments
Which Apex method are you using to unpack those Child Pages in your Post Install script? We may have bug, but we are at least attempting to account for this scenario in
RefreshPagesFromStaticResource and RefreshSkuidPages. In your Page Pack, do your pages have a value for skuid__MasterPage__r.skuid__UniqueId__c on those Child Pages?
public without sharing class InstallScript_CheetahBMS implements InstallHandler {
public static final String NAMESPACE_PREFIX = 'CheetahBMS';
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;
}
}
"skuid__MasterPage__c":"a04j000000AIaOnAAL","skuid__MasterPage__r":{"attributes":{"type":"skuid__Page__c","url":"/services/data/v34.0/sobjects/skuid__Page__c/a04j000000AIaOnAAL"},"Name":"CheetahNavigation","skuid__UniqueId__c":"CheetahBMS_CheetahNavigation"}
we are using postinstall class to do multiple task:
1. assign permission set
2. populate custom settings
3. backup existing reference data
4. insert new reference data
5. upsert skuid pages
7. backup skuid page assignments
8. insert new page assignments
9. initiate batch apex (if needed)
I used skuid provided code for upserting pages with little modification. i.e. I created private method to process skuid pages like this:
And called this method form OnInstall method like this
Now when I see the tutorial (which presumably addressed master page issue), it's a class that was extended from skuid's global class InstallScript.
I was wondering how could I use this new approach to upsert pages without breaking my postinstall script. Or can I get an idea how I can update my existing method RefreshPagesInModule to handle Master Page issue.
Thanks.
I updated the method RefreshPagesInModule to handle Master and child pages and now seems to work well. Just wanted to know if I'm doing anything wrong in the method: Any Advice would be much appreciated. Thanks.