You need to sign in to do that
Don't have an account?

how to use global method in other class. Do we have to create object for that class
without creating object can we use it?
You need to sign in to do that
Don't have an account?
without creating object can we use it?
Hi,
You can create a public static method. Then you can access that method from any other class.
eg.
public class MyClass
{
public static void myMethod()
{
// Your code here
}
}
// Call it from any other class as follows:
MyClass.myMethod();
Hope this is what you are looking for!!
It depends whether your methods are static or not.
E.g.
To call the static method you wouldn't need an object:
To call the instance method you'd definitely need an object:
If you are planning to create global methods - make sure you fully understand why you need it. Most of the time public will do
global methods are used in any other class right.
static methods also we can use , then what is the use of global ?
I think Global Method can be called outside the Org.. they are mainly used for webservice ... For ORg You can make a method Public .... Static does not make sense for Accessiblity ..
Thanks
SFDC_Evolve
Quotes from the documentation:
"This means the method or variable can be used by any Apex code that has access to the class, not just the Apex code in the same application. This access modifier should be used for any method that needs to be referenced outside of the application, either in the Web services API or by other Apex code. If you declare a method or variable as global, you must also declare the class that contains it as global."
"We recommend using the global access modifier rarely, if at all. Cross-application dependencies are difficult to maintain. "
Link:
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_classes_access_modifiers.htm?SearchType=Stem
In other words, unless you'd like to create a managed package and would like others to be able to call methods from your package don't use 'global' modifier.
Hope this helps.