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
regger118regger118 

Apex webservice from ajax on sites page not working

if i disable showheader it failes calling the apex webservice but if i enable show headers it works on the sites page why is this?

 

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

Shashikant SharmaShashikant Sharma

It would be nice if you could provide some more info and some code where you are facing this problem. One direction that I can suggest to you is that when showHeader is disabled some standard style and javascripts are removed , please check whether it is not causing the issue. If so then add that style of javascript in your page.

RagingForceRagingForce

Here is some code

 

 

 

<apex:stylesheet value="{!URLFOR($Resource.JQueryUI, '/css/ui-lightness/jquery-ui-1.8.11.custom.css')}"/>
<script type="text/javascript">var __sfdcSessionId = '{!GETSESSIONID()}';</script>
<script type="text/javascript" src="/soap/ajax/21.0/connection.js"></script>
<script type="text/javascript" src="/soap/ajax/21.0/apex.js" ></script>
<script type="text/javascript" src="https://maps-api-ssl.google.com/maps/api/js?&sensor=false"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxQ82LsCgTSsdpNEnBsExtoeJv4cdBSUkiLH6ntmAr_5O4EfjDwOa0oZBQ"></script>
<apex:includeScript value="{!URLFOR($Resource.JQueryUI, '/js/jquery-1.5.1.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.JQueryUI, '/js/jquery-ui-1.8.11.custom.min.js')}"/>

<script>
  $j = jQuery.noConflict();
</script>

<script>
    $j(document).ready(function() {
        // Slide
        $j("#menu1 > li > a.expanded + ul").slideToggle("medium");
        $j("#menu1 > li > a").click(function() {
            $j(this).toggleClass("expanded").toggleClass("collapsed").parent().find('> ul').slideToggle("medium");
    });
});
</script>

<script type="text/javascript">
  var map = null;
  var iterator = 0;
  var gInfoWindow = null;
  var gCircles = [];
  var gLocMarkers = [];
  var gContextMarker = null;
  var gCityList = [];
  
  var MAP_SERVER_URL = "http://62.80.113.77:50000/mapserver/data/kml/";
  
  var Z_DEPTH = 20000;
  var DEFAULT_LAT = 31.95216223802497;
  var DEFAULT_LONG = 1.0546875;
  
  // Our global state
  var gLocalSearch;
  var gSelectedResults = [];
  var gCurrentResults = [];
  var gSearchForm;
  //Create our tiny marker icon for local search results.
  var gRedIcon = new google.maps.MarkerImage("{!URLFOR($Resource.LocationMapContent, 'markers/marker_squared_violet.png')}", new google.maps.Size(34, 34));
  var osmCopyRight = "Map data by <a target=\"_blank\" href=\"http://www.openstreetmap.org/\">OpenStreetMap</a>,&nbsp;License&nbsp;"
    + "<a target=\"_blank\" href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA</a>";
  
  var osmMapType = new google.maps.ImageMapType({
        getTileUrl: function(coord, zoom) {
            return "http://tile.openstreetmap.org/" +
                zoom + "/" + coord.x + "/" + coord.y + ".png";
        },
        tileSize: new google.maps.Size(256, 256),
        isPng: true,
        alt: "OpenStreetMap layer",
        name: "OSM",
        maxZoom: 19
  });
  
  function Initialize(){
      var myOptions = {
          zoom: 14,
          center: new google.maps.LatLng({!Location__c.Latitude__c}, {!Location__c.Longitude__c}),
          mapTypeControl: true,
          mapTypeId: google.maps.MapTypeId.ROADMAP,
          mapTypeControlOptions: {
              mapTypeIds: ["OSM", google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, 
                google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.TERRAIN],
              style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
          },
          zoomControl: true,
          zoomControlOptions: {
                style: google.maps.ZoomControlStyle.SMALL
          },
          scaleControl: true,
          scrollwheel: false
      }
    
      var mapDiv = document.getElementById("map_canvas");
      map = new google.maps.Map(mapDiv, myOptions);
      map.mapTypes.set("OSM", osmMapType);
      map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
      gInfoWindow = new google.maps.InfoWindow({content: "loading..."});
      AddOSMLicense();   
      google.maps.event.addListener(map, "maptypeid_changed", OnMapTypeChanged);
      CreateRadiusRings();
      SetupDefaultMarkers();
      SetupDefaultLayers();
      ResetMapOnInvalidLocation();
      LoadLocalSearch();
  }

AddMarkers(sforce.apex.execute("CLocationGoogleMapService", "GetLocationsInCity", {cityName:cityName}), map);

 

this line in particular

 

AddMarkers(sforce.apex.execute("CLocationGoogleMapService", "GetLocationsInCity", {cityName:cityName}), map);

 

now if i don't show header this does not work, otherwise if enabled the apex ajax works on the sites page.

 

I have made sure that the sites user has this visual page enabled and has access to the objects in question and checked field level security.

hemantgarghemantgarg

I have implemented it , that time it was working perfectly, but now suddenly it is broken, Now the remote action is returning to an error saying "unable to connect to the server" . Its unstable feature.

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.

DaveedDaveed
I ran into this same issue while developing inside a sites community. I found the solution was to remove the url segment identifying the community. "example.cs18.force.com/some" -> "example.cs18.force.com/"
JoshuaDaviesJoshuaDavies
I ran into the same problem recently.  I was able to fix it by changing:

<apex:includeScript value="soap/ajax/31.0/connection.js"/>

to:

<script src="soap/ajax/31.0/connection.js"></script>

Apparently, when you use "<apex:includeScript>", the script is inserted before the standard salesforce scripts, but when you use <script> directly, your script runs after the salesforce scripts; it looks like one of the standard scripts needed to run before connection.js to get it to work correctly in the portal.