Uncaught reference error: sforce is not defined

I have a vf component in a page which includes a static resource. In the resource, I have a apex method call. Since I am using the same resource in a custom button also, I am using AJAX tool kit instead of @RemoteAction. So, I have added connection.js and apex.js files in the component. When the page is loaded, I see this error in console.

enter image description here

my component includes the files like this:

 <apex:includeScript value="/soap/ajax/32.0/connection.js"/>
 <apex:includeScript value="/soap/ajax/32.0/apex.js"/>
 <apex:includeScript value="{!$Resource.myStaticResource}"/>    

From the javascript console, I understand that sforce is not recognized by browser, but I’m loading the connection.js file before apex.js. What could be the issue here?

Update:

Does browser or its cache memory has to do anything with this? because If I refresh the page after I saw this issue in dev console of Chrome, …the error is gone. Why the sforce object is not recognized in the first load of the page itself?

Answer

Can you try this.

<script src="/soap/ajax/32.0/connection.js" type="text/javascript"/>
<script src="/soap/ajax/32.0/apex.js" type="text/javascript"/>
<apex:includeScript value="{!$Resource.myStaticResource}"/>

Attribution
Source : Link , Question Author : sam_s , Answer Author : Seesh

Leave a Comment