Activity Forums Salesforce® Discussions What are the Salesforce annotations? List all of them.

  • shradha jain

    Member
    July 31, 2018 at 1:30 pm

    Hello Madhulika,

    Apex annotations modify the way a method or class is used. Below is the list of annotations supported by Salesforce:

    @Deprecated:
    Use the deprecated annotation to identify methods, classes, exceptions, enums, interfaces, or variables that can no longer be referenced in subsequent releases of the managed package in which they reside. This is useful when you are refactoring code in managed packages as the requirements evolve. New subscribers cannot see the deprecated elements, while the elements continue to function for existing subscribers and API integrations.

    @Future:
    Use the future annotation to identify methods that are executed asynchronously. When you specify future, the method executes when Salesforce has available resources.
    To test methods defined with the future annotation, call the class containing the method in a startTest, stopTest code block. All asynchronous calls made after the startTest method are collected by the system. When stopTest is executed, all asynchronous processes are run synchronously.

    @IsTest:
    Use the isTest annotation to define classes or individual methods that only contain code used for testing your application. The isTest annotation is similar to creating methods declared as testMethod.

    @ReadOnly:
    The @ReadOnly annotation allows you to perform unrestricted queries against the Force.com database. All other limits still apply. It's important to note that this annotation, while removing the limit of the number of returned rows for a request, blocks you from performing the following operations within the request: DML operations, calls to System.schedule, calls to methods annotated with @future, and sending emails.

    @RemoteAction:
    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.

    @TestVisible:
    Use the TestVisible annotation to allow test methods to access private or protected members of another class outside the test class. These members include methods, member variables, and inner classes. This annotation enables a more permissive access level for running tests only.

    Apex REST annotations:

    @RestResource(urlMapping='/yourUrl'):
    The @RestResource annotation is used at the class level and enables you to expose an Apex class as a REST resource.

    @HttpDelete:
    The @HttpDelete annotation is used at the method level and enables you to expose an Apex method as a REST resource. This method is called when an HTTP DELETE request is sent and deletes the specified resource.

    @HttpGet:
    The @HttpGet annotation is used at the method level and enables you to expose an Apex method as a REST resource. This method is called when an HTTP GET request is sent and returns the specified resource.

    @HttpPatch:
    The @HttpPatch annotation is used at the method level and enables you to expose an Apex method as a REST resource. This method is called when an HTTP PATCH request is sent and updates the specified resource.

    @HttpPost:
    The @HttpPost annotation is used at the method level and enables you to expose an Apex method as a REST resource. This method is called when an HTTP POST request is sent and creates a new resource.

    @HttpPut:
    The @HttpPut annotation is used at the method level and enables you to expose an Apex method as a REST resource. This method is called when an HTTP PUT request is sent and creates or updates the specified resource.

  • Anurag

    Member
    July 31, 2018 at 1:33 pm

    Hi Madhulika,

    The main use of annotation is to instruct the compiler that the class is to be used as the specific class as defined by the annotation. Annotations are defined with an initial @ symbol, followed by the appropriate keyword.

    Apex supports the following annotations.
    @AuraEnabled
    @Deprecated
    @Future
    @InvocableMethod
    @InvocableVariable
    @IsTest
    @ReadOnly
    @RemoteAction
    @SuppressWarnings
    @TestSetup
    @TestVisible

    Apex REST annotations:
    @RestResource(urlMapping='/yourUrl')
    @HttpDelete
    @HttpGet
    @HttpPatch
    @HttpPost
    @HttpPut

  • shariq

    Member
    September 17, 2018 at 11:52 pm

    Hi,

    An Apex annotation modifies the way that a method or class is used, similar to annotations in Java. Annotations are defined with an initial @ symbol, followed by the appropriate keyword.
    To add an annotation to a method, specify it immediately before the method or class definition.

    Apex supports the following annotations.

    @AuraEnabled
    @Deprecated
    @Future
    @InvocableMethod
    @InvocableVariable
    @IsTest
    @ReadOnly
    @RemoteAction
    @TestSetup
    @TestVisible

    Apex REST annotations:

    @RestResource(urlMapping=’/yourUrl’)
    @HttpDelete
    @HttpGet
    @HttpPatch
    @HttpPost
    @HttpPut

    Hope this helps.

  • Parul

    Member
    September 18, 2018 at 8:38 pm

    I want to add some points:

    An apex annotation modifies the way a method or class is used similar to annotations in Java
    Annotations are defined with an initial @ symbol, followed by the appropriate keyword.
    To add an annotation to a method, specify it immediately before the method or class definition.
    Types of Salesforce annotations

    @ Deprecated
    @ Future
    @ Is test
    @ Read-only
    @ Remote action

     

    Thanks

Log In to reply.

Popular Salesforce Blogs