Apex Reference Guide

Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Salesforce Platform server, in conjunction with calls to the API. This reference guide includes built-in Apex classes, interfaces, enums, and exceptions, grouped by namespace. It also includes Apex DML statements to insert, update, merge, delete, and restore data in Salesforce.

For information on the Apex development process, see Apex Developer Guide.

In API version 51.0 and earlier, Apex Reference information was included in the Apex Developer Guide in the “Apex Language Reference” section.

Keep these guidelines in mind regarding API version usage:

  • Salesforce strongly recommends that you use the latest available API version.
  • If you can’t upgrade to the latest version yet, use API versions released in the past three years, for improved performance, security, and compatibility.
  • To reduce complexity, consolidate your Apex codebase to use the minimal number of API versions, ideally, just one API version.

For a non-exhaustive list of major Apex behavior changes across API versions, organized by version number, see Apex Versioned Behavior Changes.

  • Apex Release Notes

    Use the Salesforce Release Notes to learn about the most recent updates and changes to Apex.

  • Apex DML Operations

    You can perform DML operations using the Apex DML statements or the methods of the Database class. For lead conversion, use the convertLead method of the Database class. There is no DML counterpart for it.

  • ApexPages Namespace

    The ApexPages namespace provides classes used in Visualforce controllers.

  • AppLauncher Namespace

    The AppLauncher namespace provides methods for managing the appearance of apps in the App Launcher, including their visibility and sort order.

  • Approval Namespace

    The Approval namespace provides classes and methods for approval processes.

  • Auth Namespace

    The Auth namespace provides an interface and classes for single sign-on into Salesforce and session security management.

  • Cache Namespace

    The Cache namespace contains methods for managing the platform cache.

  • Canvas Namespace

    The Canvas namespace provides an interface and classes for canvas apps in Salesforce.

  • ChatterAnswers Namespace

    The ChatterAnswers namespace provides an interface for creating Account records.

  • CommerceBuyGrp Namespace

    The CommerceBuyGrp namespace provides classes and methods for retrieving information about the buyer groups associated with a user.

  • CommerceExtension Namespace

    Use the CommerceExtension namespace to define resolution strategies for registered Commerce extensions.

  • CommerceOrders Namespace

    The CommerceOrders namespace provides classes and methods to place orders with integrated pricing, configuration, and validation.

  • CommercePayments Namespace

    Use the CommercePayments namespace to provide a safe and customizable platform for managing customer payments and refunds.

  • CommerceTax Namespace

    Manage the communication between Salesforce and an external tax engine.

  • commonserviceexcellence Namespace

    The commonserviceexcellence namespace provides classes used in financial account FlexCards. These classes are documented in the Agentforce Financial Services Developer Guide.

  • ComplianceMgmt Namespace

    The ComplianceMgmt namespace provides classes and methods to implement rule processors for compliance control.

  • Compression Namespace

    The Compression namespace provides classes and methods to create and extract zip files.

  • ConnectApi Namespace

    The ConnectApi namespace (also called Connect in Apex) provides classes for accessing the same data available in Connect REST API. Use Connect in Apex to create custom experiences in Salesforce.

  • Context Namespace

    The Context namespace provides classes and methods to manage the sharing and consumption of business application data by using Context Service.

  • Database Namespace

    The Database namespace provides classes used with DML operations.

  • Datacloud Namespace

    The Datacloud namespace provides classes and methods for retrieving information about duplicate rules. Duplicate rules let you control whether and when users can save duplicate records within Salesforce.

  • DataRetrieval Namespace

    The DataRetrieval namespace provides classes and methods to record details of customer-agent engagements, as well as transcripts of their conversations.

  • DataSource Namespace

    The DataSource namespace provides the classes for the Apex Connector Framework. Use the Apex Connector Framework to develop a custom adapter for Salesforce Connect. Then connect your Salesforce organization to any data anywhere via the Salesforce Connect custom adapter.

  • DataWeave Namespace

    The DataWeave namespace provides classes and methods to support the invocation of DataWeave scripts from Apex.

  • Dom Namespace

    The Dom namespace provides classes and methods for parsing and creating XML content.

  • embeddedai Namespace

    The embeddedai namespace provides classes and methods to manage and represent records and data in Apex to support embedded AI features.

  • EventBus Namespace

    The EventBus namespace provides classes and methods for platform events and Change Data Capture events.

  • ExternalService Namespace

    The ExternalService namespace provides dynamically generated Apex service interfaces and Apex classes for complex object data types.

  • Flow Namespace

    The Flow namespace provides a class for advanced access to flows from Apex such as from Visualforce controllers and asynchronous Apex.

  • Flowtesting Namespace

    The flowtesting namespace provides dynamically generated Apex classes for flow tests that are created in Flow Builder.

  • flowuiruntime Namespace

    The classes and methods in this namespace are reserved for internal use only or future use.

  • FormulaEval Namespace

    The FormulaEval namespace provides classes and methods to evaluate dynamic formulas for SObjects and Apex objects. Use the methods to avoid unnecessary DML statements to recalculate formula field values or evaluate dynamic formula expressions.

  • disputemanagement Namespace

    The disputemanagement namespace classes provide services for Integration Procedures used by the Transaction Dispute Management OmniScript. These classes are documented in the Agentforce Financial Services Developer Guide.

  • fsccashflow Namespace

    The fsccashflow namespace provides classes used in the FSCCashFlow FlexCards and their child FlexCards. These classes are documented in the Agentforce Financial Services developer guide.

  • fsccomplaintmanagement Namespace

    The fsccomplaintmanagement namespace classes provide data helper functions for use in complaint management. These classes are documented in the Agentforce Financial Services Developer Guide.

  • fschousehold Namespace

    The fschousehold namespace provides classes used for households, financial accounts, goals, and plans. These classes are documented in the Agentforce Financial Services Developer Guide.

  • fscserviceprocesses Namespace

    The fscserviceprocesses namespace provides classes used in service process OmniScripts, such as change address and fee reversal. These classes are documented in the Agentforce Financial Services Developer Guide.

  • fscwmgen Namespace

    The fscwmgen namespace provides an interface and classes used for record alerts. These are documented in the Agentforce Financial Services Developer Guide.

  • industriespersonalizedfinance Namespace

    The industriespersonalizedfinance namespace classes provide data helper functions for use in personalized finance. These classes are documented in the Agentforce Financial Services Developer Guide.

  • Functions Namespace

    The Functions namespace provides classes and methods used to invoke and manage Salesforce Functions.

  • ise_bots_apex Namespace

    The ise_bots_apex namespace provides classes and properties to facilitate dynamic content generation and data handling for menu-driven bot interactions. Create and manage dynamic menu items that adapt to user inputs, context, and underlying object data.

  • IssueCreditMemo Namespace

    The IssueCreditMemo namespace provides classes to create and apply credit memos against invoices or invoice lines based on dispute adjustments.

  • ind_mfg_sample_mgmt_apex Namespace

    The ind_mfg_sample_mgmt_apex namespace provides classes and properties to manage the lifecycle and documentation of product requirements in manufacturing. Create, update, or version Product Requirement Specification records to ensure sample data remains consistent and compliant with production standards.

  • industriesNlpSvc

    Stores the objects used in Industries Einstein Natural Language Processing (NLP) services.

  • IndustriesDigitalLending Namespace

    The industriesDigitalLending namespace provides classes used in the Digital Lending OmniScripts and Integration Procedures.

  • Invocable Namespace

    The Invocable namespace provides classes for calling invocable actions from Apex.

  • InvoiceWriteOff Namespace

    The InvoiceWriteOff namespace provides classes to create credit memos with the total charge amount on the invoice as the write-off amount.

  • IsvPartners Namespace

    The IsvPartners namespace provides a class associated with Salesforce ISV partner use cases, such as optimizing code, providing great customer trial experiences, and driving feature adoption.

  • KbManagement Namespace

    The KbManagement namespace provides a class for managing knowledge articles.

  • LxScheduler Namespace

    The LxScheduler namespace provides an interface and classes for integrating Salesforce Scheduler with external calendars.

  • Messaging Namespace

    The Messaging namespace provides classes and methods for Salesforce notifications and email functionality.

  • Metadata Namespace

    The Metadata namespace provides classes and methods for working with custom metadata in Salesforce

  • PlaceQuote Namespace

    The PlaceQuote namespace provides classes and methods to create or update quotes with pricing preferences and configuration options.

  • Pref_center Namespace

    The Pref_center namespace provides an interface, classes, and methods to create and retrieve data in forms in Preference Manager. Preference Manager, previously called Preference Center, is a feature within the Privacy Center app.

  • Process Namespace

    The Process namespace provides an interface and classes for passing data between your organization and a flow.

  • QuickAction Namespace

    The QuickAction namespace provides classes and methods for quick actions.

  • renew_assets_summary Namespace

    The renew_assets_summary namespace provides classes that retrieve details about renewable assets to create renewal opportunities.

  • Reports Namespace

    The Reports namespace provides classes for accessing the same data as is available in the Salesforce Reports and Dashboards REST API.

  • RevSignaling Namespace

    The RevSignaling namespace provides classes to extend the standard procedure plan implementation through custom logic. A procedure plan helps you set up your procedures, configure the procedure execution settings, and relate them to a context definition in one centralized location based on your requirements.

  • RevSalesTrxn Namespace

    The RevSalesTrxn namespace provides classes and methods to create a sales transaction, such as a quote or an order, with integrated pricing and configuration.

  • RichMessaging Namespace

    Provides objects and methods for handling content in enhanced Messaging channels.

  • RulesAppln Namespace

    The RulesAppln namespace contains output classes that store details about a rules-based application of payments and credits.

  • runtime_industries_cpq Namespace

    The runtime_industries_cpq namespace provides classes and methods to search products or to manage products, catalogs, and categories.

  • runtime_industries_insurance Namespace

    The runtime_industries_insurance namespace provides options classes for insurance operations, such as creating and updating insurance quotes, generating insurance clauses, and running insurance rating.

  • Schema Namespace

    The Schema namespace provides classes and methods for schema metadata information.

  • Search Namespace

    The Search namespace provides classes for getting search results and suggestion results.

  • setup_flow_performance Namespace

    The class and methods in this namespace are for internal use only.

  • SF_Archive Namespace

    The SF_Archive namespace provides classes for testing Apex code that calls Archive Apex.

  • Sfc Namespace

    The Sfc namespace contains classes used in Salesforce Files.

  • Sfdc_Checkout Namespace

    The Sfdc_Checkout namespace provides an interface and classes for B2B Commerce apps in Salesforce.

  • Sfdc_Enablement Namespace

    The sfdc_enablement namespace provides classes for creating custom learning items to implement custom exercise types in Enablement programs. Lightning web components are used to render the custom exercises on Program Builder.

  • sfdc_surveys Namespace

    The sfdc_surveys namespace provides an interface for shortening survey invitations.

  • sfdw Namespace

    Contains classes that describe Digital Wallet consumption card status and the alerts triggered when consumption crosses a threshold.

  • sfsqlquery Namespace

    Contains classes for executing SQL queries against Data 360 data spaces from Apex.

  • Site Namespace

    The Site namespace provides an interface for rewriting Sites URLs.

  • Slack Namespace

    The Slack Namespace provides tools designed to accelerate and ease the process of developing Slack apps on the Salesforce platform.

  • Support Namespace

    The Support namespace provides an interface used for Case Feed.

  • System Namespace

    The System namespace provides classes and methods for core Apex functionality.

  • TerritoryMgmt Namespace

    The TerritoryMgmt namespace provides an interface used for territory management.

  • TxnSecurity Namespace

    The TxnSecurity namespace provides an interface used for transaction security.

  • UserProvisioning Namespace

    The UserProvisioning namespace provides methods for monitoring outbound user provisioning requests.

  • VisualEditor Namespace

    The VisualEditor namespace provides classes and methods for interacting with the Lightning App Builder. The classes and methods in this namespace operate on Lightning components, which include Lightning web components and Aura components.

  • Wave Namespace

    The classes in the Wave namespace are part of the CRM Analytics Analytics SDK, designed to facilitate querying CRM Analytics data from Apex code.

  • Appendices