0

All I have been finding is webservice examples where they query something from salesforce, or insert a basic SObject like a contact or lead or account...

I am wanting to set up an apex webservice class that will access methods from a packaged class, but have not been able to find any examples on how this is done.

Can anyone point me in the right direction on accessing another classes methods from a webservice class? As well as what the urlMapping would need to be for @RestResource tag?

Thank you very much!

1 Answer 1

1

You do this in exactly the same way as you would call another class from any other (non-webservice) class. That is, you create a new instance of your target class, store it in a variable, and then call your method (or ClassName.staticMethodName() in the case of static methods).

The webservice keyword is basically just a hint for Salesforce to invoke the automagical process that they use to allow that class to be accessed via http requests.

2
  • Do I put the webservice keyword before the method I want to access? Or in the method of my webservice class that is accessing it? Sep 8, 2017 at 18:44
  • 1
    @TylerDahle no. It is literally no different from calling A.methodB() from inside class C. For these types of questions, one of the best things to do is to try playing around with it for yourself in a sandbox. Curiosity and failure are both magnificent teachers, and you'll learn a lot more if you try getting your hands a little dirty before asking for help.
    – Derek F
    Sep 8, 2017 at 18:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .