Skip to main content

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 &amp;&amp; !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>

Hi Conlan,

Due to changes in the Banzai release, we revised our sample code for a Apex post-install script. You can review the changes here: http://help.skuid.com/m/11217/l/121145-packaging-your-skuid-pages

In essence the changes now call some core Skuid code which handles page update scenarios which the old sample code does not accommodate, for instance Master/Child Pages (a Banzai feature). I’m not sure why your post-install script is failing, but I recommend switching to the revised post-install script code. It’s simpler, and calls core Skuid methods, so the burden is on Skuid to maintain the code rather than you 🙂


Thanks Zach, just gave this a try, and the test class failed for the method: PageTrigger_PreventProtectedPageModifications


Is there something I’m missing here?



Did you modify all 3 files? The trigger and both Apex Classes?


I wasn’t able to add that Trigger to the Skuid Page object. I just kept getting this message…



I also tried removing NAMESPACE_PREFIX since I didn’t see that in the new Banzai code, but got the same compile error.


So, I went ahead and removed the PageTrigger test method from the test class, which allowed the unit test to pass…


however, the Post-Install Script is still not inserting the updated pages.


Is it possible the post-install script is not working because my test deployment org is running Rockaway and my Dev org where I built the app is running Banzai…?


Oops – looks like the trigger code in our documentation was incorrect — you need to replace “NAMESPACE_PREFIX” with “MODULE_NAME”. I updated the documentation to correct this.

I’d make this fix, re-add in the trigger and then re-run your tests.

Also, did you ensure that you re-packaged your module pages, using “Package Pages in Module”, before uploading the new package?


Conlan, I have tested upgrading pages created in a managed package development org that is on Banzai, uploading a new version, and installing the new version into a Rockaway org — the pages successfully updated for me.

Do any pages update? Or none at all?


Thanks Zach, worked great on all fronts!

Just for future reference, on their end the Post-Install script will install the most updated pages from my packaged module, but on my end I will need to re-package my pages into the module each time I make changes to my pages?

Also, the trigger is great in “protecting” the pages from modifications, but is there also a way to completely hide the XML of these pages so they can’t be copied and pasted?


I think maybe it was just confusion on my end about the re-packaging you mentioned. See my question above…


Correct - if you’ve changed Skuid Pages and want these changes to get into a new version of your package, you will need to re-package the pages in your Module. 


Regarding the page XML, no, there’s no way to hide the XML.


Thanks!


Reply