Newer Version Available
Version Class
Namespace
Usage
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.
Example
1if (System.requestVersion() == new Version(1,0))
2{
3 // Do something
4}
5if ((System.requestVersion().major() == 1)
6 && (System.requestVersion().minor() > 0)
7 && (System.requestVersion().minor() <=9))
8{
9 // Do something different for versions 1.1 to 1.9
10}
11else if (System.requestVersion().compareTo(new Version(2,0)) >= 0)
12{
13 // Do something completely different for versions 2.0 or greater
14}Version Constructors
The following are constructors for Version.
Version Methods
The following are methods for Version. All are instance methods.
compareTo(version)
Signature
public Integer compareTo(System.Version version)
Parameters
- version
- Type: System.Version
Return Value
Type: Integer
Returns one of the following values:
- zero if the current package version is equal to the specified package version
- an Integer value greater than zero if the current package version is greater than the specified package version
- an Integer value less than zero if the current package version is less than the specified package version
Usage
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.
major()
Signature
public Integer major()
Return Value
Type: Integer
minor()
Signature
public Integer minor()
Return Value
Type: Integer
patch()
Signature
public Integer patch()
Return Value
Type: Integer