You need to sign in to do that
Don't have an account?
The Tooling API isn't enforcing the package version dependency in the class/trigger metadata
I recently encountered an org with Apex classes and triggers that had dependencies on a third party managed package (http://salesforce.stackexchange.com/q/76791/102).
The Apex Classes and triggers had -meta.xml files like:
All of these were lower than the First Installed Version Number in the package details under installed packages.

As such, none of the affected Apex classes/triggers can be deployed/updated via the Metadata API without encountering the error:
The affected triggers and classes can be successfully updated with the Tooling API, and hence the developer console.
This leaves a couple of questions:
The Apex Classes and triggers had -meta.xml files like:
<?xml version="1.0" encoding="UTF-8"?> <ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>29.0</apiVersion> <packageVersions> <majorNumber>1</majorNumber> <minorNumber>1785</minorNumber> <namespace>loan</namespace> </packageVersions> <status>Active</status> </ApexTrigger>Note that it requires v1.1785 of the managed package with the loan namespace. The other triggers and classes had a range of minor versions, such as 1783, 1794 and 1795.
All of these were lower than the First Installed Version Number in the package details under installed packages.

As such, none of the affected Apex classes/triggers can be deployed/updated via the Metadata API without encountering the error:
triggers/foo.trigger-meta.xml -- Error: The specified Package Version number does not exist for that Package: loan, 1.1783
The affected triggers and classes can be successfully updated with the Tooling API, and hence the developer console.
This leaves a couple of questions:
- How did the org get into a state where there are Apex classes and triggers deployed that require a managed package version that isn't installed.
- Why isn't the Tooling API enforcing the managed package dependencies in the same way the metadata API is?
So it would appear the problem started with the change set allowing the Apex class with the dependancy on v1.0 being deployed to produciton. That, or the "First Installed Version Number" in the sandbox isn't correct after refreshing it from production.
Could you please email me at ssrivatsavaya@salesforce.com with the org Id, login access, and exact replication steps in detail so that I can investigate on this issue?
Thanks,
Shashank
Hi Shashank,
That is similar. However, I think it is distinct from the issue I’m encountering. That known issue is around version checking for extension packages not being enforced during installation but then preventing subsequent deployment to another org.
My issue is that that the deployment to production is not being prevented when the apex classes have a dependency on a managed package version that isn’t available in the target org. Subsequent refreshes of sandbox orgs from production then create an inconsistent state where the apex classes can’t be updated via the metadata api.
Thanks,
Daniel