function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How can I retrieve a list of installed packages using Apex?



I have recently been testing the ability to create extension packages to my base package. The reason for this is that I need to deliver some custom functionality for exporting data to external systems.


I need my base package to be able to display a list of "landing pages" for each extension package that is deployed. This will enable me to provide a list of supported export formats (e.g.. Export to X system, Export to Y system...)


My plan was to create a record in a custom object that would maintain the list of extension packages that are currently installed in an organisation. This record would be created on install of the extension package, not through an OnInstallCompleted event (which would have been nice!) but by an admin navigating to a page and clicking Complete Installation!


In Apex how do I retrieve a list of currently installed packages? I cannot find any reference to an Apex Package object. I am assuming Salesforce are using this to display the page in Setup which shows the currently installed packages. Is there any way I can get to this?


I also considered deploying my own tab from the extension package too. However, it seems that I cannot access tabs through the API either, so I cannot assign the tab to one of the Custom Applications in my base package. Any ideas on this one would be great too.





You could use Apex Code reflection to determine the presence of a class, assuming the class is global (so, a "marker" class, if you will). Take a look at the documentation on System.Type. It's also possible to query ApexClass (at least in v25.0) to obtain a list of classes, which can then be instantiated with System.Type.newInstance().