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
sfdcfoxsfdcfox 

sforce.apex.execute not working with Sites with namespace

Using Payment Connect, our Sites URL appears as follows:

 

 

https://<org-name>.secure.force.com/pmtx/<page-name>

 

 

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:

 

 

sforce.apex.execute('MyClass','MyFunction',{})

The AJAX toolkit forms the following SOAP URL:

 

 

 

https://<org-name>.secure.force.com/services/Soap/package/<class-name>

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:

 

 

https://<org-name>.secure.force.com/pmtx/services/Soap/package/<class-name>

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:

 

 

 

UserContext.siteUrlPrefix='pmtx'

This resulting in the following SOAP URL being generated:

 

 

https://<org-name>.secure.force.com/pmtx/pmtx/services/Soap/package/<class-name>

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?