Package Methods

A package version is a number that identifies the set of components uploaded in a package. The version number has the format majorNumber.minorNumber.patchNumber (for example, 2.1.3). The major and minor numbers increase to a chosen value during every major release. The patchNumber is generated and updated only for a patch release.

The package methods are used by package developers to customize behavior for different package versions. They allow the package developer to continue to support existing behavior in classes and triggers in previous package versions while continuing to evolve the code.

The package methods rely on special objects to allow a class to exhibit different behavior when it references different package versions. These objects can only be used in classes that are in a managed package.

Package.Version.Request
Apex classes and triggers are saved with the version settings for each installed managed package that the Apex class or trigger references. This context object represents the package version referenced by the class or trigger.
Note
You cannot use the Package.Version.Request object in unmanaged packages.
Package.Version.majorNumber.minorNumber
This object represents a package version referenced by the class or trigger.
For example, Package.Version.2.1 represents version 2.1 of the package. You can use this object together with Package.Version.Request to specify different behavior for different package versions. You can only use this object to refer to a Managed - Released package version. You cannot use it to reference Managed - Beta package versions.
Name Arguments Return Type Description
isGreaterThan Package Version Package.Version.major.minor Boolean Returns true if the package version is greater than the package version specified in the argument. For example:
if (Package.Version.Request == Package.Version.1.0)
{
    // do something 
    
}
else if (Package.Version.Request.isGreaterThan(Package.Version.2.0))
{
    // do something different 
    
}
else if (Package.Version.Request.isGreaterThan(Package.Version.2.3))
{
    // do something completely different 
    
}
isGreaterThanOrEqual Package Version Package.Version.major.minor Boolean Returns true if the package version is greater than or equal to the package version specified in the argument.
isLessThan Package Version Package.Version.major.minor Boolean Returns true if the package version is less than the package version specified in the argument.
isLessThanOrEqual Package Version Package.Version.major.minor Boolean Returns true if the package version is less than or equal to the package version specified in the argument.

For more information, see Versioning Apex Code Behavior.

© Copyright 2000–2012 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.