---
schema_version: "1"
id: 7f3a84952dd21e3f14b8f0b887137f7db3de1f62a02f34ecb0089cda47c07437
title: ApexClass
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/api_meta/meta_classes.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_classes.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4999e10b200a7e4873661d89592d5b0275f992e9010df2e26ae265eb51e8a1d7
description: Represents an Apex class. An Apex class is a template or blueprint from which Apex objects are created. Classes consist of other classes, user-defined methods, variables, exception types, and static initialization code.
---
# ApexClass

Represents an Apex class. An Apex class is a template or blueprint from which Apex objects are created. Classes consist of other classes, user-defined methods, variables, exception types, and static initialization code.

For more information, see the [Lightning Platform Apex Code Developer's Guide](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/ "html (New Window)"). This type extends the [MetadataWithContent](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_metadatawithcontent.htm "MetadataWithContent is the base type for all metadata types that contain content, such as documents or email templates. It extends Metadata. You can’t edit this object.") metadata type and inherits its content and fullName fields.

![Note](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/images/icon_note.png)

#### Note

By default, you can’t deploy updates to an Apex class if there are one or more active jobs for that class. To deploy updates in this case, do one of the following.

- Cancel Apex jobs before deploying changes to Apex code. Reschedule the jobs after the deployment.
- Enable deployments with Apex jobs in the Salesforce user interface in the Deployment Settings page.

## Supported Calls

All Metadata API calls except [CRUD-Based Calls](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_crud_based_calls_intro.htm "Use CRUD-based calls to work with metadata components in a manner similar to how synchronous API calls in the enterprise WSDL act upon objects."), 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.cls-meta.xml.

Apex classes are stored in the classes folder in the corresponding package directory.

## Version

Apex classes are available in API version 10.0 and later.

## Fields

This metadata type contains the following fields:

<table class="featureTable sort_table" summary="">



          <thead class="thead sorted" align="left">
            <tr>
              <th class="featureTableHeader  " id="d244591e144">Field Name</th>

              <th class="featureTableHeader  " id="d244591e147">Field Type</th>

              <th class="featureTableHeader  " id="d244591e150">Description</th>

            </tr>

          </thead>

          <tbody class="tbody">
            <tr>
              <td class="entry" headers="d244591e144" data-title="Field Name"><span class="keyword parmname" id="api_version"><a name="api_version"><!-- --></a>apiVersion</span></td>

              <td class="entry" headers="d244591e147" data-title="Field Type">double</td>

              <td class="entry" headers="d244591e150" data-title="Description">
                <p class="p" id="apiversion_desc"><a name="apiversion_desc"><!-- --></a>The API version for this class. Every class
                  has an API version specified at creation.</p>

              </td>

            </tr>

            <tr>
              <td class="entry" headers="d244591e144" data-title="Field Name"><span class="keyword parmname">content</span></td>

              <td class="entry" headers="d244591e147" data-title="Field Type">base64</td>

              <td class="entry" headers="d244591e150" data-title="Description">
                <span class="ph" id="content_desc"><a name="content_desc"><!-- --></a>The Apex class definition.</span> Base 64-encoded binary data.
                Before 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 handled for you by a SOAP client. <span class="ph" id="inherited_MetadataWithContent"><a name="inherited_MetadataWithContent"><!-- --></a>This field is inherited from
                  the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_metadatawithcontent.htm" title="MetadataWithContent is the base type for all metadata types that contain content, such as documents or email templates. It extends Metadata. You can’t edit this object.">MetadataWithContent</a>
                  component.</span>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d244591e144" data-title="Field Name"><span class="keyword parmname">fullName</span></td>

              <td class="entry" headers="d244591e147" data-title="Field Type">string</td>

              <td class="entry" headers="d244591e150" data-title="Description">The Apex class name. <span class="ph" id="fullName_allowed_chars"><a name="fullName_allowed_chars"><!-- --></a>The name can only contain
                  characters, letters, and the underscore (_) character, must
                  start with a letter, and can’t end with an underscore or contain
                  two consecutive underscore characters.</span> This field is
                inherited from the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/metadata.htm" title="The base class for all metadata types. You can’t edit this object. A component is an instance of a metadata type.">Metadata</a> component.</td>

            </tr>

            <tr>
              <td class="entry" headers="d244591e144" data-title="Field Name"><span class="keyword parmname" id="field_packageVersions"><a name="field_packageVersions"><!-- --></a>packageVersions</span></td>

              <td class="entry" headers="d244591e147" data-title="Field Type">
                <a class="xref" href="#PackageVersion">PackageVersion</a>[]
              </td>

              <td class="entry" headers="d244591e150" data-title="Description">
                <span class="ph" id="field_packageVersions_desc"><a name="field_packageVersions_desc"><!-- --></a>The list of installed managed package versions
                  that are referenced by this Apex class.</span>
                <p class="p" id="versions_more_info"><a name="versions_more_info"><!-- --></a>For more
                  information about managed packages, see <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.264.0.sfdx_dev.meta/sfdx_dev/sfdx_dev_dev2gp.htm" target="_blank" title="HTML (New Window)">Second-Generation Managed
                    Packages</a> in the <cite class="cite">Salesforce DX Developer
                    Guide</cite>. This field is available in API version 16.0
                  and later.</p>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d244591e144" data-title="Field Name"><span class="keyword parmname">status</span></td>

              <td class="entry" headers="d244591e147" data-title="Field Type">ApexCodeUnitStatus (<a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_objects_intro.htm#enumeration_title">enumeration</a> of type string)</td>

              <td class="entry" headers="d244591e150" data-title="Description">
                <p class="p" id="status_desc"><a name="status_desc"><!-- --></a>The status of the Apex class. The following string values are valid:</p>

                <ul class="ul bulletList">
                  <li class="li">
                    <samp class="codeph nolang">Active</samp> - The class is
                    active.
                  </li>


                  <li class="li">
                    <samp class="codeph nolang">Deleted</samp> - The class is marked for deletion. This
                    value is useful for managed packages, because it allows a
                    class to be deleted when a managed package is updated.
                  </li>

                </ul>

                <p class="p">ApexCodeUnitStatus includes an <samp class="codeph nolang">Inactive</samp> option, but
                  it’s only supported for <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_triggers.htm" title="Represents an Apex trigger. A trigger is Apex code that executes before or after specific data manipulation language (DML) events occur, such as before object records are inserted into the database, or after records have been deleted.">ApexTrigger</a>; it isn’t supported
                  for ApexClass.</p>

              </td>

            </tr>

          </tbody>

        </table>

## PackageVersion

PackageVersion identifies a version of a managed package. A package version is a number that identifies the set of components included 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’s available in API version 16.0 and later.

See [Set Package Versions for Apex Classes and Triggers](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/apex_manpkgs_subscriber_version.htm "HTML (New Window)") in the Apex Developer Guide.

<table class="featureTable sort_table" summary="">



          <thead class="thead sorted" align="left">
            <tr>
              <th class="featureTableHeader  " id="d244591e334">Field Name</th>

              <th class="featureTableHeader  " id="d244591e337">Field Type</th>

              <th class="featureTableHeader  " id="d244591e340">Description</th>

            </tr>

          </thead>

          <tbody class="tbody">
            <tr>
              <td class="entry" headers="d244591e334" data-title="Field Name"><span class="keyword parmname">namespace</span></td>

              <td class="entry" headers="d244591e337" data-title="Field Type">string</td>

              <td class="entry" headers="d244591e340" data-title="Description">Required. In a packaging context, a namespace prefix is a one to
                15-character alphanumeric identifier that distinguishes your package
                and its contents from packages of other developers on AppExchange.
                Namespace prefixes are case-insensitive. For example, ABC and abc
                aren’t recognized as unique. Your namespace prefix must be globally
                unique across all Salesforce orgs.<p class="p">Salesforce automatically
                  prepends your namespace prefix, followed by two underscores
                  (“__”), to all unique component names in your
                  Salesforce organization. A unique package component is one that
                  requires a name that no other component has within Salesforce,
                  such as custom objects, custom fields, custom links, s-controls,
                  and validation rules. For more information about namespaces, see
                  <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.pkg2_dev.meta/pkg2_dev/sfdx_dev_dev2gp_create_namespace.htm" target="_blank">Create
                    and Register Your Namespace</a> in the
                  <cite class="cite">Second-Generation Managed Packaging Developer
                    Guide</cite>.
                </p>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d244591e334" data-title="Field Name"><span class="keyword parmname">majorNumber</span></td>

              <td class="entry" headers="d244591e337" data-title="Field Type">int</td>

              <td class="entry" headers="d244591e340" data-title="Description">Required. The major number of the package version. <span class="ph" id="version_number_format"><a name="version_number_format"><!-- --></a>A package version number has a
                  <var class="keyword varname">majorNumber.minorNumber</var>
                  format.</span>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d244591e334" data-title="Field Name"><span class="keyword parmname">minorNumber</span></td>

              <td class="entry" headers="d244591e337" data-title="Field Type">int</td>

              <td class="entry" headers="d244591e340" data-title="Description">Required. The minor number of the package version. A package
                version number has a <var class="keyword varname">majorNumber.minorNumber</var>
                format.</td>

            </tr>

          </tbody>

        </table>

## Declarative Metadata Sample Definition

The following sample creates the MyhelloWorld.cls class, and the corresponding MyHelloWorld.cls-meta.xml metadata file.

MyHelloWorld.cls file:

public class MyHelloWorld {
// This method updates the Hello field on a list
// of accounts.
public static void addHelloWorld(Account\[\] accs){
	for (Account a:accs){
		if (a.Hello\_\_c != 'World')
		a.Hello\_\_c = 'World';
		}
	}
}

MyHelloWorld.cls-meta.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion\>68.0</apiVersion\>
</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](https://developer.salesforce.com/docs/atlas.en-us.264.0.api_meta.meta/api_meta/file_based_zip_file.htm).

#### See Also

- [ApexTrigger](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_triggers.htm "Represents an Apex trigger. A trigger is Apex code that executes before or after specific data manipulation language (DML) events occur, such as before object records are inserted into the database, or after records have been deleted.")