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.
A called component can check the version against which the caller was compiled using the System.requestVersion method and behave differently depending on the caller’s expectations. This allows you to continue to support existing behavior in classes and triggers in previous package versions while continuing to evolve the code.
The value returned by the System.requestVersion method is an instance of this class with a two-part version number containing a major and a minor number. Since the System.requestVersion method doesn’t return a patch number, the patch number in the returned Version object is null.
The System.Version class can also hold also a three-part version number that includes a patch number.
if (System.requestVersion() == new Version(1,0)) { // Do something } if ((System.requestVersion().major() == 1) && (System.requestVersion().minor() > 0) && (System.requestVersion().minor() <=9)) { // Do something different for versions 1.1 to 1.9 } else if (System.requestVersion().compareTo(new Version(2,0)) >= 0) { // Do something completely different for versions 2.0 or greater }
The following are constructors for Version.
The following are methods for Version. All are instance methods.
public Integer compareTo(System.Version version)
Type: Integer
Returns one of the following values:
If a two-part version is being compared to a three-part version, the patch number is ignored and the comparison is based only on the major and minor numbers.
public Integer major()
Type: Integer
public Integer minor()
Type: Integer
public Integer patch()
Type: Integer