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

Logging into Salesforce from outside Salesforce using connection.js



I have a page where I have used the "connection.js" to Login into a Salesforce instance.


But I am receiving errors when I try to do this.


When I host it from a Local Server or on a Salesforce Sites page, I get the error:


[Exception... "Access to restricted URI denied"  code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)"  location: " Line: 594"]


Can anyone tell me why this error occurs? And what should be done for successful Login?


I have provided my code below. Its a simple JS code that calls the Login method.



================ CODE ==============================



<script src="" ></script>

<script type="text/javascript" >

function logincall()

    sforce.connection.serverUrl = '';
    var usrname = document.getElementById('userid').value;
    var passwrd = document.getElementById('passid').value;

    if(usrname == null || usrname == '' || passwrd == null || passwrd == '')
        alert('Please enter Username AND Password');
    var result = sforce.connection.login(usrname, passwrd);

    alert("Logged in with session id " + result.sessionId);





To test logging into a Salesforce Instance using the connection.js "login" call

            <td><input type="text" id="userid" value="" /></td>
            <td><input type="password" id="passid" value="" /></td>


    <input type="button" value="Login" onclick="logincall();" />




================ CODE ==============================

AWESOME!! now what's that supposed to mean?

Where you able to resolve this? I am also trying to access AJAX toolkit through HTML. Any help would be great.


If you're trying to use the ajax toolkit from a page that's not from, then its not going to work, because the browser will enforce the cross domain policy, stoping the connection. Typically in these scenarios you need to look at things like jsonp (not currently supported by salesforce) or have a server proxy (i.e. the server handling your html will proxy ajax requests to salesforce, so that the browser only talks to one domain.), obviously, you need to be careful about security issues if you go this route.

Ranu JainRanu Jain


i am facing the same u solved this?  please  suggest ..i really need the solution.






I am trying the same and i am getting the same error message. Any help will be appreciated.