---
schema_version: "1"
id: 757ecf4a458a4b3b0fcaf21d543413ae303185829599b5f86e2a1c8970cafdf7
title: Using Apex
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/apex/apex-intro.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/apex-intro.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: f80578388b9cb91dadabe4474ddfe2058e35c1ac51afdd068f6d2a24400b2619
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Using Apex

Use Apex to write server-side code, such as controllers and test classes. Use Apex only if you need to customize your user interface to do more than what Lightning Data Service allows, such as using a SOQL query to select certain records. Apex provisions data that’s not managed and you must handle data refresh on your own.

Apex controllers handle requests from client-side controllers. For example, a client-side controller might handle an event and call an Apex controller action to persist a record. An Apex controller can also load your record data.

Use Apex in these scenarios:

-   To work with objects that aren’t [supported by User Interface API](https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_get_started_supported_objects.htm), such as Task and Event.
-   To work with operations that User Interface API doesn’t support, like loading a list of records by criteria (for example, to load the first 200 Accounts with Amount \> $1M).
-   To perform a transactional operation. For example, to create an account and create an opportunity associated with the new account. If either create fails, the entire transaction is rolled back.
-   To call a method imperatively, such as in response to clicking a button, or to delay loading to outside the critical path.

-   **[Creating Server-Side Logic with Controllers](https://developer.salesforce.com/docs/platform/aura-platform/controllers-server/controllers-server-intro.md)**  


    The framework supports client-side (JavaScript) and server-side (Apex) controllers. An event is always wired to a client-side controller action, which can in turn call an Apex controller action. For example, a client-side controller might handle an event and call an Apex controller action to persist a record.

-   **[Testing Your Apex Code](https://developer.salesforce.com/docs/platform/aura-platform/apps/apps-packaging-tests.md)**  


    Before you can upload a managed package, you must write and execute tests for your Apex code to meet minimum code coverage requirements. Also, all tests must run without errors when you upload your package to AppExchange.

-   **[Making API Calls from Apex](https://developer.salesforce.com/docs/platform/aura-platform/guide/apex-api-calls.md)**  


    Make API calls from an Apex controller. You can’t make Salesforce API calls from JavaScript code.

-   **[Make Long-Running Callouts with Continuations](https://developer.salesforce.com/docs/platform/aura-platform/guide/apex-continuations.md)**  


    Use the `Continuation` class in Apex to make a long-running request to an external web service. Process the response in a callback method. Continuations are the preferred way to manage callouts because they can provide substantial improvements to the user experience.

-   **[Creating Components in Apex](https://developer.salesforce.com/docs/platform/aura-platform/guide/apex-using-components.md)**  


    Creating components on the server side in Apex, using the `Cmp.<myNamespace>.<myComponent>` syntax, is deprecated. Use `$A.createComponent()` in client-side JavaScript code instead.


