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
Sandeep001Sandeep001 

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) 
BulentBulent
For unauthenticated access there is no session id.

All Answers

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


Thanks,
NG
Sandeep001Sandeep001

<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 >

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

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:
UserContext.initialize({"userId":"005c0000000IktF","siteUrlPrefix":"/leadimport"});

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
http://boards.developerforce.com/t5/Force-com-Sites/Apex-webservice-from-ajax-on-sites-page-not-working/td-p/290173
http://boards.developerforce.com/t5/Force-com-Sites/sforce-apex-execute-giving-error-in-Sites-hosted-on-Prod-org-na6/m-p/138463#M978

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.