Is it possible to detect if the package within which code is running is beta? I know
System.requestVersion() can return the version number but it can't tell if package is beta or released.
I'll start with a quick acknowledgement that you want to do this directly in Apex. I don't think this is currently possible. With the right API call it might be possible to access that information with a callout from Apex...
At first I thought you could use the Metadata API to query the InstalledPackage Metadata via the Apex Wrapper Salesforce Metadata API project. I was going to suggest checking the
FileProperties.manageableState that comes back to see if it has a value other that 'released'. However, even Beta managed packages appear to have the 'released' value.
With that failing, something like ApexTrigger.ManageableState from the Tooling API sounded promising. (Lots of other records available via the Tooling API also have this field available.)
Indicates the manageable state of the specified component that is contained in a package:
In testing that came back with 'installed' rather than the expected 'beta'. Perhaps that status only applies to the packaging org.
As a last ditch attempt I did a retrieve via the Metadata API to get the full details for the installed package. Within the resulting zipFile the packageName.InstalledPackage xml file had:
<?xml version="1.0" encoding="UTF-8"?> <InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata"> <versionNumber>1.5 (Beta 1)</versionNumber> </InstalledPackage>
Note the "(Beta 1)" appended to the versionNumber.
So, the data is available in a very round about way. Getting to it from Apex will be difficult, as it is locked away in a zip.
You might find it easier to:
- Screen scrap the Installed Packages page and check the Version Number column for "(Beta" where the row has a matching Namespace Prefix.
- Use a Custom Setting that can be configured after installation to indicate if it is a beta install or not.
- Use a Custom Metadata Type record that gets set appropriately before the package is created.
All of these approaches have downsides, so pick your poison.
You might be able to find something in the IdeaExchange to vote on, or create your own idea to expose the Beta flag on Version.
I did just find that the Force.com IDE has a special CallOptions Client ID that can access the InstalledPackageVersion. It's still an API call, but in includes all sorts out useful columns, such as VersionName and Description. These could be used to identify an Beta package indirectly via naming conventions.