5

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?

2 Answers 2

3

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}"/>
5
  • Thanks for the answer Seesh, I have already tried this one but it did not work. Besides, I couldn't recall the reason but I read that apex:includeScript should be the best practice when compared to script tag.
    – sam_s
    Sep 11, 2015 at 19:37
  • May be any server issue?! Did you try to put a full path in the script?
    – Seesh
    Sep 11, 2015 at 19:46
  • fullpath might not be a reliable one because, I have to maintain the different versions of the code in different sandboxes. Also, I found that it is working for me (I have sys-admin profile) sometimes but If I logged-in as another user for the same profile it doesn't at all. Wierd.
    – sam_s
    Sep 11, 2015 at 20:48
  • I understand. My attempts are ways to troubleshoot. Once the page loads without exceptions, we could figure out the cause and workaround with the best practice. Working sometimes is a good news, you can generate and monitor the debug log and post any updates.
    – Seesh
    Sep 11, 2015 at 22:26
  • @sam_s in your original post, the syntax for getting a static resource is off. It should be {!$Resource.myStaticResource}.
    – martin
    Sep 12, 2015 at 0:42
0

https://developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/sforce_api_ajax_vf_sample.htm

It think in order for it to work you need to include the session ID like so:

<apex:page >
<script type="text/javascript">
var __sfdcSessionId = '{!GETSESSIONID()}';
</script>

<script src="../../soap/ajax/41.0/connection.js" type="text/javascript"></script>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .