+ Start a Discussion
business Identitybusiness Identity 

Invoking a method of a class from another class

Hello,

Consider a class A with function A, The function is global & static (for remote invocation) & another class B with function B which is also global & static. I need to invoke the function A from within function B. How do I do it??
Anoop yadavAnoop yadav
Hi,

Try with the below code.
global class A {
    
    global void methodA(){
        System.debug('METHOD-A');
    }
}
global class B {
    
    global void methodB(){
        System.debug('METHOD-B');
        A aClass = new A();
        aClass.methodA();
    }
}


 
Naveen Rahul 3Naveen Rahul 3
Another Way

global class A {
    
    global void methodA(){
		System.debug('METHOD-A');
    }
}

global class B  Extends A{
    
    global void methodB(){
        System.debug('METHOD-B');
        var variablename = A.methodA();
        
    }
}

Without initialize 

Thanks
D Naveen Rahul.