Contents
What happens if a method is static?
When a variable is declared as static, then a single copy of variable is created and shared among all objects at class level. Static variables are, essentially, global variables. All instances of the class share the same static variable.
Why is my method static?
A static method belongs to the class rather than object of a class. A static method invoked without the need for creating an instance of a class. static method can access static data member and can change the value of it. A static method can be accessed just using the name of a class dot static name . . .
When should use static method?
When you want to have a variable that always has the same value for every object of the class, forever and ever, make it static . If you have a method that does not use any instance variables or instance methods, you should probably make it static .
What do you need to know about future methods?
Use @future annotation before the method declaration. Future methods must be static methods, and can only return a void type. The specified parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types. Future methods can’t take standard or custom objects as arguments.
Can a future method return a void type?
Future methods must be static methods, and can only return a void type. The specified parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types.
How to test future methods in Test class?
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.
How is the future method used in Salesforce?
Salesforce uses a queue-based framework to handle asynchronous processes from such sources as future methods and batch Apex. This queue is used to balance request workload across organizations. Use the following best practices to ensure your organization is efficiently using the queue for your asynchronous processes.