---
schema_version: "1"
id: 6dac31ddae3f15ff6d10d27e910b6ca0e1235d174caf421f3f1cdfdf9a8c42f3
title: Invoking Apex
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_invoking.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_invoking.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 322a8258b2b9ecb725b3d2831bbb624f372d7731551083ee747557082ff7336e
description: You can run Apex code with triggers, or asynchronously, or as SOAP or REST web services.
---
# Invoking Apex

You can run Apex code with triggers, or asynchronously, or as SOAP or REST web services.

1. [Anonymous Blocks](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_anonymous_block.htm)  
    An anonymous block is Apex code that doesn’t get stored in the metadata, but that you can compile and execute.
2. [Triggers](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm)  
    Apex can be invoked by using triggers. Apex triggers enable you to perform custom actions before or after changes to Salesforce records, such as insertions, updates, or deletions.
3. [Asynchronous Apex](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_async_overview.htm)  
    Apex offers multiple ways for running your Apex code asynchronously. Choose the asynchronous Apex feature that best suits your needs.
4. [Exposing Apex Methods as SOAP Web Services](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_web_services.htm)  
    You can expose your Apex methods as SOAP web services so that external applications can access your code and your application.
5. [Exposing Apex Classes as REST Web Services](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest.htm)  
    You can expose your Apex classes and methods so that external applications can access your code and your application through the REST architecture.
6. [Apex Email Service](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_inbound_what_is.htm)  
    You can use email services to process the contents, headers, and attachments of inbound email. For example, you can create an email service that automatically creates contact records based on contact information in messages.
7. [Using the InboundEmail Object](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_inbound_using.htm)  
    For every email the Apex email service domain receives, Salesforce creates a separate InboundEmail object that contains the contents and attachments of that email. You can use Apex classes that implement the Messaging.InboundEmailHandler interface to handle an inbound email message. Using the handleInboundEmail method in that class, you can access an InboundEmail object to retrieve the contents, headers, and attachments of inbound email messages, as well as perform many functions.
8. [Visualforce Classes](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_pages.htm)  
    In addition to giving developers the ability to add business logic to Salesforce system events such as button clicks and related record updates, Apex can also be used to provide custom logic for Visualforce pages through custom Visualforce controllers and controller extensions.
9. [JavaScript Remoting](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_invoking_javascript_remoting.htm)  
    Use JavaScript remoting in Visualforce to call methods in Apex controllers from JavaScript. Create pages with complex, dynamic behavior that isn’t possible with the standard Visualforce AJAX components.
10. [Apex in AJAX](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_and_ajax.htm)  
    The AJAX toolkit includes built-in support for invoking Apex through anonymous blocks or public webservice methods.