function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepu sfdcDeepu sfdc 

how to access methods from other class ?

Hi,
   I have Employee class and its having 4 methods.. i have another class name is Manager. So i want to access Employee class methods in Manager class . can you tell me how to achieve this ?

 
Best Answer chosen by Deepu sfdc
JyothsnaJyothsna (Salesforce Developers) 
Hi Deepu,

 Create an instance for the first class in second class. For example
 
class Manager {

  public Manager(){

//create Instance for first class

EmployeeClass emp=new EmployeeClass();

emp.method1();


}

}
If the first class is static class you can directly access that method using class name. For example
 
EmployeeClass.method1();

Hope this helps you!

Please mark the answer as Best Answer if it really helped so that it would help others as well in future.


Best Regards,
Jyothsna

All Answers

JeffreyStevensJeffreyStevens
Manager.methodname();
JyothsnaJyothsna (Salesforce Developers) 
Hi Deepu,

 Create an instance for the first class in second class. For example
 
class Manager {

  public Manager(){

//create Instance for first class

EmployeeClass emp=new EmployeeClass();

emp.method1();


}

}
If the first class is static class you can directly access that method using class name. For example
 
EmployeeClass.method1();

Hope this helps you!

Please mark the answer as Best Answer if it really helped so that it would help others as well in future.


Best Regards,
Jyothsna
This was selected as the best answer