Similar to Java annotations, an Apex annotation alters the way a function or class is utilized. This blog will help you learn more about Salesforce annotations as well as the types of annotations available.
For Example:
global class My Class {
@ future
Public static void my Method (string a)
{
// long – running Apex code
}
}
If you want to enrich your career and become a professional in Salesforce CRM, then enroll in "Salesforce Online Training". This course will help you to achieve excellence in this domain. |
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 managing packages as the requirement evolve.
Public void my method (string a) { }?
[ Check out How to Create Dashboard in Salesforce? ]
1. Use future annotation to identify a method that is executed asynchronously. When you specify the future, the method executes when Salesforce has available resources.
2. For e.g. 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).
3. Methods with the future annotation must be static methods, and can only return a void type.
4. To make a method in a class execute asynchronously, define the method with the future annotation.
For Example:
global class My future class {
@ future
static void My method (string a, integer i) {
System. Debug (‘Method called with: ‘+a+’ and ‘+i);
// do callout
}
}
5. How to specify if a method executes a callout:
@ future (callout = true )
public static void do callout from future ()
{
// Add code to perform callout
}
6. You can specify (callout = false) to prevent a method from making callouts.
7. It is used to make call outs.
8. One common call-out is Web service.
9. All Web services are callouts.
1. Use the isTest annotation to define classes and individual methods that only contain code used for testing your application.
2. The isTest annotation is similar to creating methods declared as a test method.
3. Classes defined with the isTest annotation don’t count against your org limit of 2 MB for all apex code individual methods defined.
4. Classes and methods defined as isTest can be either private or public..Classes defined as isTest must be top-level classes.
Example:
@ isTest
Private class My Class {
@ isTest static void test 1 () {
}
@ isTest static void test 2 () {
}
}
Example:
A Public test class that contains utility methods for test data creation:
@ isTest
public class TestUtil {
public static void create Test Accounts () {
}
public static void create Test Contacts () {
}
[ Related Article: Test Class in Salesforce ]
Check out Top Salesforce Interview Questions and Answers that help you grab high-paying jobs |
1. It provides support for Apex methods used in VF to be called via JavaScript, this process is often referred to as JavaScript Remoting.
2. Methods with the Remote Action annotation must be both global and static.
3. To use JavaScript Remoting in a VF page, you add the request as a Java Script invocation, which must take the following form:
[]. (
[params….,]
<(Call back function>(result,event) {
// callback function logic
}, {escape: true});
4. The namespace is your organization’s name, this is required only if the class comes from an installed package.
5. The Controller is the name of your Apex controller.
6. The method is the name of the Apex method you have been calling.
7. Params are the comma-separated list of parameters that your method holds.
8. Call back function is the name of the JavaScript function that will handle the response from the controller call back function and receives the status of the method call and the produces result as parameters.
9. Escape specifies whether your Apex methods, the response must be escaped (by default, true) or not (false).
10. In your controller, your Apex method declaration is processed with the @rotation annotation like this.
@remote action
Global static string gets an item ID (string, object name) (….)
Are you looking to get trained on Salesforce, we have the right course designed according to your needs. Our expert trainers help you gain the essential knowledge required for the latest industry needs. Join our Salesforce Certification Training program from your nearest city.
Salesforce Training Chennai, Salesforce Training Dallas, Salesforce Training Bangalore, Salesforce Training Hyderabad, Salesforce Training Mumbai, Salesforce Training Delhi, Salesforce Training Noida, Salesforce Training New York, Salesforce Training Chicago, Salesforce Training Kolkata, Salesforce Training Gurgaon, Salesforce Training Pune.
These courses are equipped with Live Instructor-Led Training, Industry Use cases, and hands-on live projects. Additionally, you get access to Free Mock Interviews, Job and Certification Assistance by Certified Salesforce Trainers.
Related Articles:
Shallow copy and Deep Copy in Cloud Computing - Salesforce
SalesForce Integration and Environment in Cloud Computing
MindMajix offers different Salesforce certification training according to your desire with hands-on experience on Salesforce concepts:
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Salesforce Training | Nov 19 to Dec 04 | View Details |
Salesforce Training | Nov 23 to Dec 08 | View Details |
Salesforce Training | Nov 26 to Dec 11 | View Details |
Salesforce Training | Nov 30 to Dec 15 | View Details |
Arogyalokesh is a Technical Content Writer and manages content creation on various IT platforms at Mindmajix. He is dedicated to creating useful and engaging content on Salesforce, Blockchain, Docker, SQL Server, Tangle, Jira, and few other technologies. Get in touch with him on LinkedIn and Twitter.