Annotations in Apex in Salesforce.com

Annotations in Apex in Salesforce.com

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.

Apex supports the following annotations:

1. @Deprecated
2. @Future
3. @IsTest
4. @ReadOnly
5. @RemoteAction
6. @TestVisible

Apex REST annotations:

1. @RestResource(urlMapping=’/yourUrl’)
2. @HttpDelete
3. @HttpGet
4. @HttpPatch
5. @HttpPost
6. @HttpPut

@future annotation in Salesforce:
     Use the future annotation to identify methods that are executed asynchronously. When you specify future, the method executes when Salesforce has available resources.

     For example, you can use the future annotation when making an asynchronous Web service callout to an external service. Without the annotation, the Web service callout is made from the same thread that is executing the Apex code, and no additional processing can occur until the callout is complete (synchronous processing).

Note:
     1. Methods with the future annotation must be static methods and can only return a void type.
     2. The specified parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types.
     3. Methods with the future annotation cannot take sObjects or objects as arguments.

Cheers!!!

Leave a Reply