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

Call web service from Salesforce.

I want to know what is the best way to call a web service from Salesforce.

The process involves
From an Contact SF page...
1.Call a webservice that I host in my webserver
2.Creating a task associated with the contact based on the webservice result

What the best way to authenticate in my web service
1 - Should I create a UsernameWs/PasswordWs Field in the User Object and pass it
2 - pass the sessionId

I unfortunately don't have an answer, just wanted to add that this is something I have been looking for an answer to as well, so hopefully some genius comes by here and gives us a good nudge in the right direction :)
I tried to consume web services using Javascript
and I received "permission denied" javascript error (I found that it relates to some kind of cross-domain protection) in the folowing code
<script language="javascript">   
function UseWS(){

try{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
return false;}
xmlhttp.Open("POST",url,false);  ---------------- Error
So using js to consume an external web service doesn't work
So the question "how to consume webservices in SF"  is very ACTIVE
Please help me

there is no good way to consume a web service from within

you are better off having an externally hosted application poll the api.  ie, your externally hosted application can poll every hour, look for the contacts that fit your criteria, and then add tasks based on your business requirements.  in this case you would want your salesforce username and

another option is to create a custom link (which will need to be clicked) that calls a .jsp or .aspx or whatever kind of server processing enabled page that then accesses your webservice.  you can pass any of your contact record field data through the url.  once you have completed your processing, you can call the api to update your contact with the proper tasks (or whatever).  in that case you will need to pass the valid sessionId to be used by all of your application's calls back to the api.  the nice thing about this is it takes advantage of your session management rules in as well.

hope that helps.



"in this case you would want your salesforce username and "

should read:

in this case you would want your salesforce username and password in an encrypted config file, as you will need to access to send login info to the api each time your application runs.

sorry about that...


Let me explain want I want:

I want to send a SMS to a contact

a. The user has to write the message (preferably in Salesforce) send it to my WebApplication (it could be a web service or not)

a.1 Salesforce must register a Task

a.2 After a while (up to 2 hours) the task must be Updated (SMS Delivered or Not)


Some Thoughts

1- I wanted to use a “JavaScript SOAP Client” to use the web service but it returns error (permission denied – it’s a security browser issue - see the following msgs).

What is the use of “Calling a Web Service”, it seems to me that they are only Web Links (googlemap, gmail, fedex etc).


2- Since my web application can take up to 2 hours to update the SF Task, I must do it using the .net API and save the Username and Password in the my Web App Database (the session expires in a 1 hour- so It’s out of question) , I’m I right? It could be a potential security risk.


3- Using the SF Ajax Library doesn’t returns an Error (permission denied – see 1.) Why?

I'm not entirely following the use case, but note that you cannot make a Javascript / AJAX / XML-HTTP request to any domain other than * from a client side s-control (ie HTML you store on salesforce) due to browser security restrictions.  They may explain the error you are seeing.

Seems like you are the right path to do this on the server / .NET, but not sure what issue you are encountering there.
How do i pass the sessionId and serverurl (witch variables)? I've tried to use "login" object assign to it the sessionId and serverurl but it return error: session corrupt. Can anyone send some snnipet code on how to do that?