---
schema_version: "1"
id: be60e113ad6c57d051791937834d3e604a582291558f5aed99287de992252203
title: Declaring a Remote Method in Apex
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-pages-developers-guide/guides/pages/javascript/pages-js-remoting-declaring-remote-method.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-js-remoting-declaring-remote-method.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 495e453d9d13a0e0bcc0aeeb24506e3910561e0c5d8cee7b37decc48b2bd2bcd
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# Declaring a Remote Method in Apex

You can call almost any Apex method as a JavaScript remoting remote action. To do so, the method needs to conform to some simple rules.

In your controller, your Apex method declaration is preceded with the `@RemoteAction` annotation like this:

```apex
@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`.

Methods used for JavaScript remoting must be uniquely identified by name and number of parameters; overloading isn’t possible. For instance, with the method above, you can’t also have a `getItemId(Integer productNumber)` method. Instead, declare multiple methods with different names:

-   `getItemIdFromName(String objectName)`
-   `getItemIdFromProductNumber(Integer productNumber)`

