Both Java & Apex syntax are same. 1. if Method are Static then we can invoke method: Class_Name.MethodName(); 2. If method are no-Static then: 2.1: Create instance of class 2.2: invoke method using object: Oob.MethodName();
Example: ========================================================================================================= public class MyFirstClass{
public void doOperation1(){ // Enter statement here }
public static void doOperation2(){ //Enter statement here }
} ========================================================================================================= Invoke Controller Method from Trigger //To call doOperation1() method MyFirstClass obj = new MyFirstClass(); obj.doOperation1();
//To call doOperation2() method - above i have mentioned, Static method can call directly using ClassName.Method_Name MyFirstClass.doOperation2();
Please let me know if you find any issue & need more help.
You can create instance of class and call methods from trigger and you also call static methods of class without creating a instance of class and you can create method in Trigger also,
Below links hepls you to study about handler patterns
Both Java & Apex syntax are same. 1. if Method are Static then we can invoke method: Class_Name.MethodName(); 2. If method are no-Static then: 2.1: Create instance of class 2.2: invoke method using object: Oob.MethodName();
Example: ========================================================================================================= public class MyFirstClass{
public void doOperation1(){ // Enter statement here }
public static void doOperation2(){ //Enter statement here }
} ========================================================================================================= Invoke Controller Method from Trigger //To call doOperation1() method MyFirstClass obj = new MyFirstClass(); obj.doOperation1();
//To call doOperation2() method - above i have mentioned, Static method can call directly using ClassName.Method_Name MyFirstClass.doOperation2();
Please let me know if you find any issue & need more help.
Both Java & Apex syntax are same.
1. if Method are Static then we can invoke method: Class_Name.MethodName();
2. If method are no-Static then:
2.1: Create instance of class
2.2: invoke method using object: Oob.MethodName();
Example:
=========================================================================================================
public class MyFirstClass{
public void doOperation1(){
// Enter statement here
}
public static void doOperation2(){
//Enter statement here
}
}
=========================================================================================================
Invoke Controller Method from Trigger
//To call doOperation1() method
MyFirstClass obj = new MyFirstClass();
obj.doOperation1();
//To call doOperation2() method - above i have mentioned, Static method can call directly using ClassName.Method_Name
MyFirstClass.doOperation2();
Please let me know if you find any issue & need more help.
Thanks & Regards,
Ranjeet Singh.
All Answers
You can create instance of class and call methods from trigger and you also call static methods of class without creating a instance of class and you can create method in Trigger also,
Below links hepls you to study about handler patterns
https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex_Trigger_Best_Practices
http://developer.force.com/cookbook/recipe/trigger-pattern-for-tidy-streamlined-bulkified-triggers
Below links is same question
https://developer.salesforce.com/forums/ForumsMain?id=906F000000093cKIAQ
IF it helps you than please mark it as a solution and ENJOY APEX
Both Java & Apex syntax are same.
1. if Method are Static then we can invoke method: Class_Name.MethodName();
2. If method are no-Static then:
2.1: Create instance of class
2.2: invoke method using object: Oob.MethodName();
Example:
=========================================================================================================
public class MyFirstClass{
public void doOperation1(){
// Enter statement here
}
public static void doOperation2(){
//Enter statement here
}
}
=========================================================================================================
Invoke Controller Method from Trigger
//To call doOperation1() method
MyFirstClass obj = new MyFirstClass();
obj.doOperation1();
//To call doOperation2() method - above i have mentioned, Static method can call directly using ClassName.Method_Name
MyFirstClass.doOperation2();
Please let me know if you find any issue & need more help.
Thanks & Regards,
Ranjeet Singh.