+ Start a Discussion

sforce.apex.execute giving error in Sites hosted on Prod org (na6)

Hi I am using sforce.apex.execute call from javascript in my VF page to execute a method in global method of a webservice apex class. This is working fine on Sandbox Site page but throws an error:-

{faultcode:UNKNOWN_EXCEPTION, faultstring:UNKNOWN_EXCEPTION: 'Site UNder Construction',}


when we deploy the code to production org that is hosted on na6. It also works fine in VF page on production org but on Sites page it fails.


Any thoughts why it is happening?

Best Answer chosen by Admin (Salesforce Developers) 
For unauthenticated access there is no session id.

All Answers

Hi Sandeep,
Paste your Site's VF page code here. Thanks,


<apex:includeScript value="/soap/ajax/15.0/connection.js"/>
<apex:includeScript value="/soap/ajax/15.0/apex.js"/>                       
     <script type="text/javascript">
                sforce.connection.sessionId = '{!$Api.Session_ID}'; 


               function findAddress(param){


                     var getAddress = sforce.apex.execute("UtilityClass", "globalMethod",{param1:"name"});



</ script >

For unauthenticated access there is no session id.
This was selected as the best answer

This issue actually appears to revolve around a problem with accessing webservices anonymously.
The only solution I was able to find was to set a userId and siteUrlPrefix:

and include the salesforce main.js [I downloaded it while the headers were on then saved it as a static resource]:
<apex:includeScript value="{!URLFOR($Resource.jqueryPackage, 'js/main.js')}"/>
library manually.

The solution offered by Salesforce support:
var __sfdcSessionId = '{!GETSESSIONID()}';

does not actually allow my site call to work as intended [I would still get a Site Under Construction error]:
POST https://everbank.ewmqa.cs14.force.com/services/Soap/package/PortalUserResetWS 500 (Internal Server Error) connection.js:599
Uncaught {faultcode:'UNKNOWN_EXCEPTION', faultstring:'UNKNOWN_EXCEPTION: Site under construction', } connection.js:1019

The same error is reported on these pages

Personally, I think it is ridiculous that once you say that the PAGE has access to the webservice that you need any userid at all but for now the workaround allows the page to do what it needs to do. I certainly don't believe I should need to download the main.js (which may not work after a future upgrade) and set a userId and siteUrlPrefix. Salesforce really should allow you to configure a webservice to work without a userid for their sites pages.