I have a method in one class, but I need to move it out to another class.
I’m aware this question has been asked several times already, but I’m getting an error I don’t understand.
How can I call a method from a different class?
Like so:
global with sharing class FirstController extends ThirdController{ public List<Task> getListOfObjects() { SecondController sc = new SecondController(); return sc.getAllObjects(); } } global with sharing class SecondController{ public List<Task> getAllObjects() { List<Task> myObjects; = ( //LOGIC ); return myObjects; } }
I get the follwoing error:
Method does not exist or incorrect signature: [SecondController].getAllObjects() FirstController.cls
Is there a mistake somewhere I can’t see?
Any advice or suggestions would be greatly appreciated!
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
This is what I did and am able save the class and make a call to the method in the FirstController which subsequently calls the SecondController.
global with sharing class SecondController{ public List<Task> getAllObjects() { return null; } } global with sharing class FirstController { public List<Task> getListOfObjects() { SecondController sc = new SecondController(); return sc.getAllObjects(); } }
I am not sure what your ThirdController class was so I took it out from my code.
This works just perfectly.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0