Invoking Apex

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

  • Anonymous Blocks

    An anonymous block is Apex code that doesn’t get stored in the metadata, but that you can compile and execute.

  • Triggers

    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.

  • Asynchronous Apex

    Apex offers multiple ways for running your Apex code asynchronously. Choose the asynchronous Apex feature that best suits your needs.

  • Exposing Apex Methods as SOAP Web Services

    You can expose your Apex methods as SOAP web services so that external applications can access your code and your application.

  • Exposing Apex Classes as REST Web Services

    You can expose your Apex classes and methods so that external applications can access your code and your application through the REST architecture.

  • Apex Email Service

    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.

  • Using the InboundEmail Object

    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.

  • Visualforce Classes

    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.

  • JavaScript Remoting

    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.

  • Apex in AJAX

    The AJAX toolkit includes built-in support for invoking Apex through anonymous blocks or public webservice methods.