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
lopezclopezc 

sforce.connection.login giving errors in Sites

Hi I am using sforce.connection.login call from javascript in my VF page accessible from a Site that what is does is to log a user in Salesforce (the user exists in Salesforce and it is active), but I am getting the following error:

 

{faultcode:'UNKNOWN_EXCEPTION', faultstring:'UNKNOWN_EXCEPTION: Site under construction', }

 

here is my VF page:

 

<apex:page showheader="false" standardStylesheets="false"> <apex:includeScript value="/soap/ajax/17.0/connection.js"/> <apex:includeScript value="/soap/ajax/17.0/apex.js"/> <script type="text/javascript"> function approveCrf() { try{ sforce.connection.sessionId = '{!$Api.Session_ID}'; var username = document.getElementById('un'); var password = document.getElementById('pw'); var loginResult = sforce.connection.login(username.value, password.value); }catch(error) { if (error.faultcode.indexOf("INVALID_LOGIN") != -1) { alert("check your username and passwd, invalid login"); } else { alert(error); } } } </script> <form id="loginForm"> UserName: <input type="text" id="un" size="15" value=""/><br /> Password: <input type="password" id="pw" size="15" value=""/><br /> <p><input type="button" value="Login and Approve" onclick="approveCrf();"/></p> <apex:message styleClass="locationError" /> </form> </apex:page>

Any ideas?

Thanks

Message Edited by lopezc on 12-17-2009 07:25 AM
Best Answer chosen by Admin (Salesforce Developers) 
BulentBulent

there is no session id for site access.

you need to use visualforce and apex for your queries.

and if you need authenticated access then you need to use the sites-portal integration 

Message Edited by Bulent on 12-17-2009 09:50 AM

All Answers

BulentBulent

there is no session id for site access.

you need to use visualforce and apex for your queries.

and if you need authenticated access then you need to use the sites-portal integration 

Message Edited by Bulent on 12-17-2009 09:50 AM
This was selected as the best answer
lopezclopezc
do you mean I can't use"sforce.connection.login" within the javascript in my Site? The problem is that none of the users are customer portal users or parner portal users and the authentication login in sites only enables login for those 2 profiles.
BulentBulent

Yes you can't login via javascript.

Site gives you unauthenticated access (read/create on standard objects, full access on custom objects)

 

But again this is unauthenticated access use full for web2any object flows or  search and query public information or displaying public content.

 

 

If you need to authenticate users the only supported way is to integrate with customer or partner portal products

 

 

lopezclopezc
Oh ok, and what is the "sforce.connection.login" used for?
BulentBulent

it's part of the ajax toolkit let's you login to salesforce via javascript.

Site access doesn't have a session id, so this is not supported for sites.

 

You might not need this since sites already gives you the access you might need. take a look a these two articles:

 

An Introduction To Force.com Sites

Authenticating Users on Force.com Sites

modoleamodolea

Hi,

 

I know this is an old discussion, if someone has the same issue and because I had the same..

This was probably caused by the fact that your site uses a site prefix (such as abcd.force.com/prefix).

In this case, you just need to set the serverUrl variable which is a property of the connection object in the ajax toolkit.

Here is the example I used (api 22.0) :

<script>sforce.connection.serverUrl = '{!$Site.Prefix}/services/Soap/u/22.0';</script>

 

hope this will help..

Adrian

DafuelDafuel
Hi,

I am facing the same issue where using sforce calls i am trying to insert attachments from sites to salesforce but getting sesion Id invalid error.