Newer Version Available
ApexClass
For more information, see the Lightning Platform Apex Code Developer's Guide. This type extends the MetadataWithContent metadata type and inherits its content and fullName fields.
Supported Calls
All Metadata API calls except CRUD-Based Calls, which prevents deployment outside of proper deployment lifecycle and test-execution constraints.
Declarative Metadata File Suffix and Directory Location
The file suffix is .cls for the class file. The accompanying metadata file is named ClassName-meta.xml.
Apex classes are stored in the classes folder in the corresponding package directory.
Version
Fields
This metadata type contains the following fields:
| Field Name | Field Type | Description |
|---|---|---|
| apiVersion | double |
The API version for this class. Every class has an API version specified at creation. |
| content | base64 | The Apex class definition. Base 64-encoded binary data. Prior to making an API call, client applications must encode the binary attachment data as base64. Upon receiving a response, client applications must decode the base64 data to binary. This conversion is usually handled for you by a SOAP client. This field is inherited from the MetadataWithContent component. |
| fullName | string | The Apex class name. The name can only contain characters, letters, and the underscore (_) character, must start with a letter, and cannot end with an underscore or contain two consecutive underscore characters. This field is inherited from the Metadata component. |
| packageVersions | PackageVersion[] |
The list of installed managed
package versions that are referenced by this Apex class. For more information about managed packages, see the Lightning Platform Quick Reference for Developing Packages. For more information about package versions, see “About Package Versions” in the Salesforce online help. This field is available in API version 16.0 and later. |
| status | ApexCodeUnitStatus (enumeration of type string) |
PackageVersion
PackageVersion identifies a version of a managed package. 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. It is available in API version 16.0 and later.
Declarative Metadata Sample Definition
The following sample creates the MyhelloWorld.cls class, and the corresponding MyHelloWorld.cls-meta.xml metadata file.
MyHelloWorld.cls file:
1public class MyHelloWorld {
2// This method updates the Hello field on a list
3// of accounts.
4public static void addHelloWorld(Account[] accs){
5 for (Account a:accs){
6 if (a.Hello__c != 'World')
7 a.Hello__c = 'World';
8 }
9 }
10}MyHelloWorld.cls-meta.xml:
1<?xml version="1.0" encoding="UTF-8"?>
2<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3 <apiVersion>53.0</apiVersion>
4</ApexClass>Wildcard Support in the Manifest File
This metadata type supports the wildcard character * (asterisk) in the package.xml manifest file. For information about using the manifest file, see Deploying and Retrieving Metadata with the Zip File.