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

sforce.apex.execute not working with Sites with namespace

Using Payment Connect, our Sites URL appears as follows:






In our developer organization, the page we've created works perfectly. In production, however, since there is a namespace, it appears to create some confusion. If I use the following code:




The AJAX toolkit forms the following SOAP URL:





This causes the following error to be thrown:




UNKNOWN_EXCEPTION: site under construction


I did some searching on the Forums, and found several posts related to this error, but they did not really answer the question I had. Digging deeper, I found that the correct SOAP URL should have been:




With a little bit more of a dig, I uncovered a variable called UserContext.siteUrlPrefix. I added a single line in order to attempt fixing the toolkit as follows:





This resulting in the following SOAP URL being generated:




So, this all leads up to the following question:


How do I use sforce.apex.execute in a manner that will generate the correct URL without doing some "hacks" on my part? Is this a bug of some sort with the Sites detection algorithm, or is there something more innocent that I am missing? The obvious solution is to create a new Sites page that is in the default namespace, which would resolve the issue, but how would I go about getting the correct SOAP URL generated?