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
mahi1mahi1 

Jquery script instead of <apex:page>

hi, iam using this code in my visualforcepage to execute jquery but iam getting 

Error: <apex:page> is required and must be the outermost tag in the markup at line 1 column 1   this error

my vfpage code:

&lt;apex:page showHeader=&quot;false&quot; sidebar=&quot;false&quot; standardStylesheets=&quot;false&quot;&gt;

&lt;/apex:page&gt;


any one can help.
Vamsi KrishnaVamsi Krishna
can you post your complete VF page with the javascript/jquery part as well ?

this is just the apex:page tags of your page..

<apex:page showHeader="false" sidebar="false" standardStylesheets="false">

</apex:page>
mahi1mahi1
hi Vamsi, thanks for respons

this is my vfpage code but not executing........

&lt;!-- This page is used as POC to call REST API from Visualforce --&gt;
&lt;apex:page showHeader=&quot;false&quot; sidebar=&quot;false&quot; standardStylesheets=&quot;false&quot;&gt;
&lt;style&gt;
    body
    {
        font-family: &quot;Open Sans&quot;, Helvetica, Arial, sans-serif;
        font-size : 0.8em;
    }
   lable
   {
        font-weight : bold;
   }
   .trace
   {
        background-color:
        padding : 10px;
        border: 1px solid #E0E0E0;
        background-color: #F8F8F8;
   }
   pre
   {
        font-size : 1em;
        white-space: pre-wrap; /* css-3 */
        white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
        white-space: -pre-wrap; /* Opera 4-6 */
        white-space: -o-pre-wrap; /* Opera 7 */
        word-wrap: break-word; /* Internet Explorer 5.5+ */

        line-height: 1.1em !important;
        font-family: 'Monaco', courier, monospace;
   }
   .leftDiv
   {
       width: 70%;
       float:left;
   }
   .rightDiv
   {
        width: 28%;
        float:right;
        background-color: #EEE;
        border: 1px solid #aaa;
        padding:5px;
   }
   .hlp
   {
        width: auto;
        color: #000000;
        background-color: #e5eecc;
        margin: 0px;
        padding: 5px;
        border: 1px solid #d4d4d4;
        background-image: linear-gradient( #ffffff , #e5eecc 100px);
        font-weight:bold;
        margin-top:20px;

   }
   a{
        outline: none;
        color: #21759b;
    }
    a:hover {
        color: #0f3647;
    }
    .heading {
        font-size : 2em;
        text-align : center;
        padding:10px;
        background-color: #EEE;
        font-weight : bold;
        border: 1px solid #aaa;
        margin-bottom : 10px;
        color : #21759b;
    }
&lt;/style&gt;

&lt;!-- Add remote site setting for cdnjs.cloudflare.com --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;//cdnjs.cloudflare.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;&gt; &lt;/script&gt;

&lt;div style=&quot;width:98%&quot;&gt;
    &lt;div  class=&quot;leftDiv&quot;&gt;
    &lt;div class=&quot;heading&quot;&gt;
        Salesforce REST API Playground
    &lt;/div&gt;
        HTTP Request Type :
        &lt;label for=&quot;rad-Get&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;rad-Get&quot; name=&quot;requestType&quot; value=&quot;GET&quot; checked=&quot;true&quot; /&gt;GET&lt;/label&gt;
        &lt;label for=&quot;rad-POST&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;rad-POST&quot; name=&quot;requestType&quot; value=&quot;POST&quot; /&gt;POST&lt;/label&gt;
        &lt;label for=&quot;rad-PATCH&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;rad-PATCH&quot; name=&quot;requestType&quot; value=&quot;PATCH&quot; /&gt;PATCH&lt;/label&gt;
        &lt;label for=&quot;rad-Del&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;rad-Del&quot; name=&quot;requestType&quot; value=&quot;DELETE&quot; /&gt;DELETE&lt;/label&gt;
        &lt;br /&gt;

        REST URL : &lt;input type=&quot;text&quot; id=&quot;RESTURL&quot; size=&quot;70&quot; value=&quot;/services/data/v29.0/sobjects/Account/&quot; /&gt;
        &lt;br /&gt;
        Request Data :
        &lt;textarea rows=&quot;4&quot; id=&quot;RestRequestData&quot; cols=&quot;50&quot;&gt; {}  &lt;/textarea&gt;

        &lt;input type=&quot;button&quot; id=&quot;urlEntered&quot; value=&quot;Execute Me&quot; onclick=&quot;exec()&quot; /&gt;

        &lt;br /&gt;

        &lt;div class=&quot;hlp&quot; id=&quot;helpDiv&quot;&gt;
            Replace &quot;Account&quot; in REST URL by any other SObject.
        &lt;/div&gt;
        &lt;br /&gt;
        &lt;div id=&quot;errMsg&quot; class=&quot;trace&quot; style=&quot;display:none&quot;/&gt;

    &lt;/div&gt;

    &lt;div  class=&quot;rightDiv&quot;&gt;

    &lt;h3&gt; Salesforce Documentation Reference &lt;/h3&gt;
       &lt;ul&gt;
           &lt;li&gt; &lt;a href=&quot;https://www.salesforce.com/us/developer/docs/api_rest/&quot;&gt; REST API Developers Guide &lt;/a&gt; &lt;/li&gt;
       &lt;/ul&gt;

    &lt;h3&gt; Metadata Related APIs&lt;/h3&gt;
       &lt;ul&gt;
           &lt;li&gt; &lt;a href=&quot;javascript:setVal(0);&quot;&gt; Get SObject Information &lt;/a&gt; &lt;/li&gt;
           &lt;li&gt; &lt;a href=&quot;javascript:setVal(1);&quot;&gt; List Available REST API Versions &lt;/a&gt; &lt;/li&gt;
           &lt;li&gt; &lt;a href=&quot;javascript:setVal(2);&quot;&gt; List Organization Limits&lt;/a&gt; &lt;/li&gt;
           &lt;li&gt; &lt;a href=&quot;javascript:setVal(3);&quot;&gt; List Available REST Resources &lt;/a&gt; &lt;/li&gt;
           &lt;li&gt; &lt;a href=&quot;javascript:setVal(4);&quot;&gt; Get a List of Objects &lt;/a&gt; &lt;/li&gt;
           &lt;li&gt; &lt;a href=&quot;javascript:setVal(5);&quot;&gt; Get Object's Metadata Info &lt;/a&gt; &lt;/li&gt;
       &lt;/ul&gt;

      &lt;h3&gt; Working with Records &lt;/h3&gt;
       &lt;ul&gt;
           &lt;li&gt; &lt;a href=&quot;javascript:setVal(6);&quot;&gt; Create Record &lt;/a&gt; &lt;/li&gt;
           &lt;li&gt; &lt;a href=&quot;javascript:setVal(7);&quot;&gt; Update Record &lt;/a&gt; &lt;/li&gt;
           &lt;li&gt; &lt;a href=&quot;javascript:setVal(8);&quot;&gt; Delete Record &lt;/a&gt; &lt;/li&gt;
           &lt;li&gt; &lt;a href=&quot;javascript:setVal(9);&quot;&gt; Get Field Values from Records &lt;/a&gt; &lt;/li&gt;
       &lt;/ul&gt;

    &lt;/div&gt;
&lt;/div&gt;

&lt;script&gt;

    var $errMsg = $(&quot;#errMsg&quot;);
    var $getOpt = $(&quot;#rad-Get&quot;);
    var $postOpt = $(&quot;#rad-POST&quot;);
    var $restUrl = $(&quot;#RESTURL&quot;)
    var $RestResponse = $(&quot;#RestResponse&quot;);
    var $reqData = $(&quot;#RestRequestData&quot;);
    var $helpDiv = $(&quot;#helpDiv&quot;);
    var $patch = $(&quot;#rad-PATCH&quot;);
    var $radDel = $(&quot;#rad-Del&quot;);

    var arrayOfRest = new Array();

    function exec()
    {

        var postUrl = $restUrl.val();
        var postData = $reqData.val();
        var reqType = $('input:radio[name=requestType]:checked').val();
        var heading = '&lt;h3&gt; Response : &lt;/h3&gt; &lt;br /&gt;';

        resetResult();

        $.ajax({
          type: reqType,
          beforeSend: function (xhr)
                {
                    xhr.setRequestHeader(&quot;Authorization&quot;,  'Bearer {!$API.Session_ID}');

                },
          headers : {'Content-Type' : 'application/json; charset=utf-8'},
          url: postUrl,
          data: postData,
          dataType: 'text'
        })
         .done(function( data ) {

                var res = JSON.stringify ($.parseJSON(data),null,'t');
                printResult(heading+&quot;&lt;pre&gt;&quot;+res+&quot;&lt;/pre&gt;&quot;);

          })
          .fail(function(xhr,textstatus,error){
             var output = '&lt;br /&gt; &lt;b&gt; Status : &lt;/b&gt;'+textstatus ;
             output = output +  '&lt;br /&gt; &lt;b&gt; Error : &lt;/b&gt;'+error ;
             printResult(output);
          });
    }

    function printResult(htmlVal)
    {
        $errMsg.html(htmlVal);
        $errMsg.show();
    }

    function resetResult()
    {
        $errMsg.hide();
        $errMsg.html(&quot;&quot;);
    }

    function setVal(ind)
    {
        //console.log('I am called');

        var ret = arrayOfRest[ind];

        if(ret != null)
        {
            if(ret.type == 'GET')
                $getOpt.attr('checked', 'checked');
            else if(ret.type == 'PATCH')
                $patch.attr('checked', 'checked');
            else if(ret.type == 'DELETE')
                $radDel.attr('checked', 'checked');
            else
                $postOpt.attr('checked', 'checked');

            $restUrl.val(ret.URL);
            $reqData.val(ret.Body);
            setHelpVal(ret.Help);
            resetResult();
        }

    }

    function setHelpVal(val)
    {
        if(val != null &amp;&amp; val != '')
        {
            $helpDiv.show();
            $helpDiv.html(val);
        }
        else
            $helpDiv.hide();
    }

    function createJSONData(reqType,resURL,reqBody,hlp)
    {
        return {&quot;type&quot;:reqType,&quot;URL&quot;:resURL,&quot;Body&quot;:reqBody,&quot;Help&quot;:hlp} ;
    }

    function createData()
    {
        //Dont Change Sequence
        arrayOfRest.push(  createJSONData(
                            &quot;GET&quot;,
                            &quot;/services/data/v29.0/sobjects/Account/&quot;,
                            &quot;{}&quot;,
                            'Replace &quot;&lt;i&gt;Account&lt;/i&gt;&quot; in REST URL by any other SObject.')) ;

        arrayOfRest.push(  createJSONData(
                            &quot;GET&quot;,
                            &quot;/services/data/&quot;,
                            &quot;{}&quot;,
                            &quot;Use the Versions resource to list summary information about each REST API version currently available, including the version, label, and a link to each version's root. You do not need authentication to retrieve the list of versions.&quot;)) ;

        arrayOfRest.push(  createJSONData(
                            &quot;GET&quot;,
                            &quot;/services/data/v29.0/limits/&quot;,
                            &quot;{}&quot;,
                            'This s under PILOT Program. Contact Salesforce support to enable it in your organization')) ;

        arrayOfRest.push(  createJSONData(
                            &quot;GET&quot;,
                            &quot;/services/data/v29.0/&quot;,
                            &quot;{}&quot;,
                            'Use the Resources by Version resource to list the resources available for the specified API version. This provides the name and URI of each additional resource.')) ;

        arrayOfRest.push(  createJSONData(
                            &quot;GET&quot;,
                            &quot;/services/data/v29.0/sobjects/&quot;,
                            &quot;{}&quot;,
                            'Use the Describe Global resource to list the objects available in your organization and available to the logged-in user. This resource also returns the organization encoding, as well as maximum batch size permitted in queries.')) ;

        arrayOfRest.push(  createJSONData(
                            &quot;GET&quot;,
                            &quot;/services/data/v29.0/sobjects/Account/describe&quot;,
                            &quot;{}&quot;,
                            'Replace &quot;&lt;i&gt;Account&lt;/i&gt;&quot; by Other Object Name to get Metadata Information')) ;

        arrayOfRest.push(  createJSONData(
                            &quot;POST&quot;,
                            &quot;/services/data/v29.0/sobjects/Account/&quot;,
                            '{&quot;Name&quot; : &quot;Account By REST DEMO - By Jitendra&quot;}',
                            'Replace &quot;&lt;i&gt;Account&lt;/i&gt;&quot; by Other Object Name, You will need to change JSON body also to provide rquired data for creation of record')) ;

        arrayOfRest.push(  createJSONData(
                            &quot;PATCH&quot;,
                 &quot;/services/data/v29.0/sobjects/Account/0019000000osqEaAAI&quot;,
                            '{&quot;BillingCity&quot; : &quot;Nagpur&quot;}',
                            'If Success, &lt;i&gt;It will not return anything&lt;/i&gt;')) ;

        arrayOfRest.push(  createJSONData(
                            &quot;DELETE&quot;,
            &quot;/services/data/v29.0/sobjects/Account/0019000000osqEaAAI&quot;,
                            '{}',
                            'If Success, &lt;i&gt;It will not return anything&lt;/i&gt;')) ;

        arrayOfRest.push(  createJSONData(
                            &quot;GET&quot;,
        &quot;/services/data/v29.0/sobjects/Account/0019000000osqs0?fields=AccountNumber,BillingPostalCode&quot;,
                            '{}',
                            'provide valid &lt;i&gt;RecordId&lt;/i&gt; and field names in GET URL')) ;

    }

    //Initialize Data
    createData();

&lt;/script&gt;

&lt;/apex:page&gt;