+ Start a Discussion

Quick Question

Hi all,

Given I have the Session ID and Server ID, how do I access Salesforce data?

I want to access some data from my company website. I have the following code, but it gives me a "responseDOM has no properties" error.

"<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>"

function initPage() {
    var session = document.getElementById("session").value;
    var server = document.getElementById("server").value;
    //Get Salesforce connection based on users current session id
    sforceClient.init(session, server);

    if (sforceClient.getSessionId().indexOf("!API_Session_ID") != - 1){
        alert("Could not login using API");
        return ;

What am I missing?

you can use:


function initPage() {


sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", true);





still not working :(

Message Edited by BAGEL on 04-28-2006 01:04 PM

I guess what I want to know is how to do Single Sign-On with Ajax Toolkit. If anyone can give me some examples, that would be helpful. Thanks.
You use the serverUrl and session merge fields as outlined in a previous response.

sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", true);
But I am runing the script outside of salesforce. DO "{!API_Session_ID}", "{!API_Partner_Server_URL_70}" still work?
When I read a document describe how to do single sign-on for web application, it said using


to pass the Session ID and Server.

it has examples for Java, and C#

but I need to do it with javascript/ajax toolkit. How to do that?


So, if I understand, you are not 'piggybacking' on an existing session, but want to do a fresh login.  In that case, you can just call:


sforceClient.login(user, password );




What do you mean by "running outside of salesforce"?  From the file system?  From konfabulator?  From your own web server?  Each of this are very different circumstances.  If you are running this from your file system for instance, you will never have the merge fields in the init call replaced by anything (the file system doesn't do this and that is essentially "the server" that is serving the page).  Same hold true for K, but then, you would not even try the merge fields in this case.

If from your own web server, then you need to obtain the session id and server url as url parameters on the request object as is demonstrated in the java and .NET samples, and replace the two merge fields yourself.