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
s2pid_fs2pid_f 

VisualForce and AJAX

Hi

I am writing my 1st visual force page and it is housed under setup-develop-pages

The code is very simple -

<apex:page showHeader="false" sidebar="false" >
<apex:includeScript value="/soap/ajax/15.0/connection.js"/>
<apex:includeScript value="/soap/ajax/15.0/apex.js"/>

 

  <script>
  function setupPage() {
        sforce.connection.sessionId = '{!$Api.Session_ID}';
        alert(sforce.connection.sessionId);
        var queryResult = sforce.connection.describeTabs();     
        alert('after query');
        
      
     } //end function

  </script>

 

<body onload="setupPage();">
<div id="output">HI</div>
</body>
</apex:page>

 

I am getting the 1st alert message with the session id, but the alert after api call is giving an error - {faultcode:'UNKNOWN_EXCEPTION', faultstring:'UNKNOWN_EXCEPTION: Site under construction', }

Can someone please help me with this.

thanks

Sandeep001Sandeep001

I am also facing the same error - {faultcode:'UNKNOWN_EXCEPTION', faultstring:'UNKNOWN_EXCEPTION: Site under construction', }

 

Did u get to know why this error comes?

reatlimecoreatlimeco

The following actually works.  The "onload" doesn't work as suggested in the documentation:

 

<apex:page >

<html>

 <head>

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

<script type="text/javascript">

function displayTabs(tabs) {

 

for( var i=0; i<tabs.length; i++) {

var tab = tabs[i];document.write(

" " + tab.label + " " + tab.url + " " + tab.iconUrl + " " + tab.miniIconUrl + " " + tab.sobjectName );

document.write("<br />");

}

}

 

 

 sforce.connection.sessionId = '{!$Api.Session_ID}';

try {var

result = sforce.connection.describeTabs();

} catch(error) {

document.write(error);

}for

(var i=0; i < result.length; i++) {var tabSet = result[i];

document.write (tabSet.label);

document.write("<br />");

var tabs = tabSet.get("tabs");

displayTabs(tabs);

}

</script>

</head>

<body >

 

</body>

</html>

</apex:page>

 

Took me almost 3 days to sort through the mis-information and many hours of trial and error to get this.

 

Let me know if you find a way to send this information to the underlying controller.

 

Enjoy.

reatlimecoreatlimeco

Note that "alert" don't work in Visualforce per another piece of random documentation.

 

Would be nice if they could put the rules for proper use of javascript within Visualforce all in one place.