Post-Install Script not running / pulling new pages

  • 1
  • Problem
  • Updated 3 years ago
  • Solved
  • (Edited)
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;
    }
    
}



Photo of Conlan O'Rourke

Conlan O'Rourke

  • 3,280 Points 3k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
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 :)
Photo of Conlan O'Rourke

Conlan O'Rourke

  • 3,280 Points 3k badge 2x thumb
Thanks Zach, just gave this a try, and the test class failed for the method: PageTrigger_PreventProtectedPageModifications

Is there something I'm missing here?

Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
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?
Photo of Conlan O'Rourke

Conlan O'Rourke

  • 3,280 Points 3k badge 2x thumb
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?
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
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. 
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Regarding the page XML, no, there's no way to hide the XML.
Photo of Conlan O'Rourke

Conlan O'Rourke

  • 3,280 Points 3k badge 2x thumb
Thanks!
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
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?
Photo of Conlan O'Rourke

Conlan O'Rourke

  • 3,280 Points 3k badge 2x thumb
I think maybe it was just confusion on my end about the re-packaging you mentioned. See my question above...