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
EPSWDEVEPSWDEV 

Exposing a class method as a webservice.

Hi,

I wanted to know if there is a way to expose a Apex class method as a webservice that can be called without providing a session id. In other words can I call my webservice fromt he outside world without having the web service client 'log in to the salesforce system'.

Thanks,
SuperfellSuperfell
Sorry, nope, you need a sessionId.
Andreas H.Andreas H.
So what is the suggested way to implement the following requirement:

Let's say I want to extend the "Contact" object in Salesforce with a custom field indicating that the contact has "passed a credit check". The credit check is to be performed by an external application. This might trigger a workflow in the external application, which might take a couple of days.

At some point, the external application needs to notify my Salesforce organization that the credit check for my contact has been completed, and wants to update the "Credit Check" field of the particular contact object in question.

How do you go about that?

* Do I need to create a user in Salesforce for the external application and share username/password with the external application? (I would consider this cumbersome and insecure)

* Is it better to implement an inbound e-mail handler and tell the external application to send an e-mail once the credit check has been completed for my contact?

* Do I need to implement some polling mechanism in Salesforce that is periodically polling the status of the credit check? What would be the best way to do that?

* Is it possible to create a "Formula" (or similar field) that is invoking APEX code to call out from Salesforce to a web service provided by an external application? (which would be solving the problem by following a polling approach)

* Is the "right" way to solve this problem to create a Visualforce page with an APEX controller in the background that is then invoking a web service of the external application to retrieve the outcome of the credit check?

I want to (re)use as much default functionality as possible and really follow the cleanest approach possible to implement this requirement. The idea of an inboud e-mail handler seems to be quite cumbersome, and so does the idea of creating a user in Salesforce for my external app. In the same way, I don't want to create a Visualforce page but solely rely on default behaviors - therefore, the best solution to me would be to create a custom "field" for "Contact" that is then invoking a web service on the fly as the field value is retrieved/queried by Salesforce (e.g. when the Contact record is opened) - however, looks like it's not possible to invoke web services/APEX code from within formulas of calculated fields.

Sorry if I'm asking dumb questions, but I couldn't find the right answers by skimming over the docs and presentations, and I'm quite new to Salesforce. Any feedback is highly appreciated! Thanks a lot!!!
EPSWDEVEPSWDEV
Andreas,

I would go with an email handler or developing a proxy webservice. I believe salesforce allows creation of email handles as part of their native functionality, however I have never used it so I dont know how hard or easy it would be to go down that route. An alternative would be to create a proxy service that is hosted outside salesforce and therefore accessible publicly without the use of the session id. The approach would be that the external system calls the proxy webservice which in turn calls the salesforce webserivice with a session id. this way you dont have to do any polling and instead when the data is ready it comes to your system. Apace Axis allows you to expose java methods pretty easily as a web service.

hope this helps.