ApexClass represents an Apex code unit and its class-level runtime and managed-package version settings. Its source can contain methods, variables, inner classes, exception types, and static initialization code. Classes can provide business logic, UI controllers, Flow actions, integrations, and authentication handlers.
A class asset combines Apex source with a companion metadata file. The metadata settings alone do not establish what invokes the class, which resources its code uses, or which users can access it. Those questions require examining the source and the configuration that references the class.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
The class name, inherited from the metadata base type. It must be unique, start with a letter, and contain only alphanumeric characters and underscores. It cannot end with an underscore or contain consecutive underscores. |
content |
The Apex class definition, inherited from MetadataWithContent. API transport uses base64 encoding; the local .cls file contains Apex text, not base64 text. A SOAP client handles the transport conversion. |
apiVersion |
The runtime API version specified for the class at creation. It is separate from the Metadata API version used to retrieve or deploy the asset. Changing it changes the class's runtime version context. |
packageVersions |
Versions of installed managed packages referenced by this class. Each entry requires namespace, majorNumber, and minorNumber. These entries are package-version references, not the class's own version number or an inventory of installed packages. |
status |
Supported class values are Active and Deleted. Deleted marks the class for deletion and supports removing a class during a managed-package update. Inactive is not supported for classes. |
Behavior and Constraints
A class cannot be temporarily disabled with status. Although the shared ApexCodeUnitStatus enumeration includes Inactive, that value is supported only for ApexTrigger, not ApexClass. Class lifecycle status is separate from caller configuration and user access.
apiVersion is a runtime setting, not an inventory label. Likewise, packageVersions identifies the managed-package versions referenced by this class; its nested entries do not define those packages. See Set Package Versions for Apex Classes and Triggers.
Access configuration is separate from the class asset. PermissionSet and MutingPermissionSet reference classes through apexClass. Effective user access depends on the applicable permission configuration and assignments, which the class files do not establish.
A Flow class reference does not always mean a method call. Flow can reference classes through actionName and apexClass, including references for actions and Apex-defined data types. FlowTest uses apexClass, while InvocableActionExtension uses targetName. Test-suite membership is configured separately: ApexTestSuite uses testClassName.
Code and UI assets can reference a class within their source content, represented by filedata links. These include other classes, triggers, Visualforce pages and components, and Lightning components. Such links are not separate reference elements in the class's companion XML.
Identity and security configurations select classes through their own fields: AuthProvider uses plugin and registrationHandler; ConnectedApp uses plugin and lifecycleClass; Network uses registrationHandler and headlessDiscoveryHandler; OauthTokenExchangeHandler uses tokenHandlerApex; SamlSsoConfig uses samlJitHandlerId; and TransactionSecurityPolicy uses apexClass. These configurations point to the class, not the other way around.
Integration handlers follow the same direction: EmailServicesFunction uses apexClass, PaymentGatewayProvider uses apexAdapter, and ConversationVendorInfo uses integrationClass.
Deployment and Retrieval
Apex classes are stored in the classes folder in the corresponding package directory. Each class has two files: ClassName.cls for Apex source and ClassName.cls-meta.xml for settings. Much of the class's behavior and dependency information is in the source rather than the companion XML.
ApexClass supports the * wildcard in the package.xml manifest, which selects metadata members for retrieval or deployment. This support belongs to ApexClass; the wildcard restriction documented for its MetadataWithContent base type does not apply to the class type.
Metadata API CRUD-based calls are not supported. CRUD means create, read, update, and delete operations performed through those individual calls. Metadata API changes to classes must use the deployment lifecycle, including applicable test-execution constraints, rather than bypassing it with CRUD-based calls.
By default, Salesforce blocks updates when one or more active Apex jobs exist for the class. The documented alternatives are:
- Cancel the jobs before deployment and reschedule them afterward.
- Enable deployments with Apex jobs on the Deployment Settings page in Setup.
This restriction depends on live job state and the org's deployment setting, not just the contents of the class files.
For removal during a managed-package update, status supports Deleted. For a destructive deployment, which removes named metadata components, the class is identified under ApexClass in destructiveChanges.xml. Exact member-name casing is a reported diagnostic check when that deployment cannot find an existing class.
A missing-class deployment error can also come from configuration that references the class. For example, a Profile class-access entry can reference a class absent from the destination. Including the class and its needed dependencies, or removing the unavailable access entry from the deployment, addresses that reported scenario. A possible relationship alone does not establish actual usage or a mandatory deployment sequence.
Relationships
Source references establish what a class uses; incoming configuration establishes where the class is selected or exposed. A Flow action or authentication configuration can lead through a class to other classes, objects, fields, or credentials, but only where the actual configuration and code establish that chain. The relationships below describe possible connections, not proof of use in an org.
References
-
ApexClass:filedata -
ApexPage:filedata -
CustomField:filedata -
CustomLabel:filedata -
CustomObject:filedata -
Flow:filedata -
NamedCredential:filedata
Referenced By
AIUsecaseDefinition, ApexClass, ApexComponent, ApexPage, ApexTestSuite, ApexTrigger, AppointmentSchedulingPolicy, AuthProvider, Bot, BotBlock, BotTemplate, BotVersion, CareBenefitVerifySettings, ConnectedApp, ConversationMessageDefinition, ConversationVendorInfo, CustomNotificationType, CustomObject, EmailServicesFunction, EntitlementProcess, ExternalServiceRegistration, ExtlClntAppOauthConfigurablePolicies, Flow, FlowTest, GenAiBundle, GenAiPromptTemplate, IdentityVerificationProcDef, InvocableActionExtension, LightningBundle, LightningWebComponent, MutingPermissionSet, MyDomainDiscoverableLogin, Network, OauthTokenExchangeHandler, PaymentGatewayProvider, PermissionSet, Profile, RecommendationStrategy, RegisteredExternalService, RelatedRecordAssocCriteria, SamlSsoConfig, TransactionSecurityPolicy.
Reported Issues
- A retrieval warning does not necessarily mean the org has no classes. A 2015 report showed "Entity type 'ApexClass' is not available in this organization" during retrieval. A 2016 answer suggested checking the retrieving user's profile for "Author Apex". That is a diagnostic possibility, not an established cause of every occurrence. See the retrieval availability discussion.
-
A Profile deployment can fail because of a missing class-access target. In a 2014 sandbox-to-sandbox deployment, an
apexClassaccess entry referenced a class absent from the destination. The suggested remedies were to deploy the class and its needed dependencies with the Profile, or remove the unavailable class-access entry from the deployment. See the missing class in Profile deployment discussion. -
Destructive-deployment name matching can explain a misleading missing-class warning. A 2024 answer reported that the class member name in
destructiveChanges.xmlmust match the existing class's casing. This concerns destructive-deployment identity, not Apex language identifier behavior. See the destructive changes naming discussion. -
A Flow "apexClass is invalid" error can involve generated types rather than a missing ordinary
.clsasset. A 2023 namespaced scratch-org report involved dynamic Apex types generated by External Services and associated the failure with namespace handling. A 2024 answer suppliedExternalService__{namespaceprefix}__{filename}as the generated naming pattern. This reported convention is specific to those generated types; it is not a general class naming rule or a reason to remove namespaces from unrelated deployments. See the External Services namespace discussion. -
Ordinary Apex DML was not a working route for bulk class-version changes. In a 2014 report, querying class records, changing their API versions, and issuing an Apex
updatefailed. An answer suggested changing the local metadata files and deploying them instead. This is distinct from Metadata API CRUD support. See the DML on class records discussion. -
A trigger on
ApexClasswas not available for logging class changes. A 2023 report described trigger creation as forbidden; the answer distinguished metadata deployment from ordinary record changes. See the class-change automation discussion.
Common Questions
Can I set an Apex class to Inactive?
No. ApexClass supports Active and Deleted. The shared enumeration's Inactive value applies only to ApexTrigger. Caller configuration and user access are separate from class status.
Why can't I deploy an Apex class while jobs are active?
By default, active Apex jobs for the class block updates. Cancel the jobs and reschedule them after deployment, or enable deployments with Apex jobs on the Deployment Settings page.
Which files do I retrieve for an Apex class?
The asset consists of ClassName.cls and ClassName.cls-meta.xml in the package's classes folder. The first contains Apex source; the second contains class settings. ApexClass supports wildcard selection in package.xml.
Does apiVersion need to match the Metadata API version?
They serve different purposes. The class's apiVersion sets its runtime version context, while the Metadata API version governs the retrieve or deploy request. Changing the class value changes runtime context, not merely its metadata label.
Why does a deployment say "no ApexClass named" when I am deploying permissions?
The missing reference can be in class-access configuration rather than class source. In the reported Profile deployment, the destination lacked the referenced class. The suggested remedies were to include the class and its needed dependencies or remove the unavailable access entry from the deployment.