[SalesForce] Get a user’s managed package version number through code

Our users will be using many different managed package versions. As users can be using versions which don't have the latest features, I need to know which package is being used by a user who will log in to Salesforce from an external application and invoke Apex web services.

I've been looking for a way to access this number from within Apex but I can't find anything.

This could also be accessed from the external application, and I found the following documentation which mentions the PackageVersion and PackageVersionHeader API classes. However, I don't know if this respects the logged-in user or simply lists all packages being used in SFDC, and I don't have access to the external application to check.

Does anyone have any idea how I can do this?

Best Answer

I found the Apex call System.requestVersion() which seems to solve my problem. I found this link, which gives examples of logic based on version number, to be very helpful. The Version class is also worth a look.

Related Topic