---
schema_version: "1"
id: 23d1a3ab9dab974209b189828129cb8658c74171582fc078d0d0d635b954b0d0
title: RemoteAction Annotation
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_classes_annotation_RemoteAction.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_RemoteAction.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: e66a59e6c605947da79dddf98d995577f472ded657925c1a6203779e6c8a8ba4
---
# RemoteAction Annotation

The RemoteAction annotation provides support for Apex methods used in Visualforce to be called via JavaScript. This process is often referred to as JavaScript remoting.

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

#### Note

Methods with the RemoteAction annotation must be static and either global or public.

Add the Apex class as a custom controller or a controller extension to your page.

<apex:page controller="MyController" extension="MyExtension"\>

![Warning](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/images/icon_note_warning.png)

#### Warning

Adding a controller or controller extension grants access to all @RemoteAction methods in that Apex class, even if those methods aren’t used in the page. Anyone who can view the page can execute all @RemoteAction methods and provide fake or malicious data to the controller.

Then, add the request as a JavaScript function call. A simple JavaScript remoting invocation takes the following form, where namespace, MyController, method, and callbackFunction are placeholder values.

\[namespace.\]MyController.method(
    \[parameters...,\]
    callbackFunction,
    \[configuration\]
);

Table 1. Remote Request Elements
| Element | Description |
| --- | --- |
| namespace | The namespace of the controller class. The namespace element is required if your organization has a namespace defined, or if the class comes from an installed package. |
| MyController, MyExtension | The name of your Apex controller or extension. |
| method | The name of the Apex method you’re calling. |
| parameters | A comma-separated list of parameters that your method takes. |
| callbackFunction | The name of the JavaScript function that handles the response from the controller. You can also declare an anonymous function inline. callbackFunction receives the status of the method call and the result as parameters. |
| configuration | Configures the handling of the remote call and response. Use this element to change the behavior of a remoting call, such as whether to escape the Apex method’s response. |

In your controller, your Apex method declaration is preceded with the @RemoteAction annotation like this:

@RemoteAction
global static String getItemId(String objectName) { ... }

Apex @RemoteAction methods must be static and either global or public.

Your method can take Apex primitives, collections, typed and generic sObjects, and user-defined Apex classes and interfaces as arguments. Generic sObjects must have an ID or sobjectType value to identify actual type. Interface parameters must have an apexType to identify actual type. Your method can return Apex primitives, sObjects, collections, user-defined Apex classes and enums, SaveResult, UpsertResult, DeleteResult, SelectOption, or PageReference.

For more information, see “JavaScript Remoting for Apex Controllers” in the Visualforce Developer's Guide.

- [← Previous](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_ReadOnly.htm "ReadOnly Annotation")
- [Next →](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_SuppressWarnings.htm "SuppressWarnings Annotation")