4

I'm encountering a weird issue where a VF page in my Community fails to connect to the AJAX API. (I suspect this is a bug but don't have a great track record with SF support, so I'm hoping someone here can help me.)

Background

I have a VF page which needs to manipulate dependent picklist information. Since Apex can't provide this information, I pull it into the page using the connection.js ajax api and the methology described in Get lists of dependent picklist options in Apex --

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

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

<script>
    // later on, deep in the page's code, run when page is fully loaded
    jQuery( function($) {
        objDesc = sforce.connection.describeSObject('Custom_Object__c');
    });
</script>

This is working properly in my development sandbox, with expected results.

The Problem

This week, we deployed the page to another sandbox. There are no other changes in code - the pages and related code are identical.

Nevertheless, the call to sforce.connection.describeSObject('Custom_Object__c') fails with a "500 Internal Server - Not Supported Error". I dug into the network panel to investigate why.

In Sandbox A, the connection calls the following URL: /prefix/services/Soap/u/29.0, which works
In Sandbox B, the connection calls /services/Soap/u/29.0 -- which does not work.

In the initialization in connection.js, this URL is set by calling UserContext.getUrl('/services/Soap/u/29.0'); UserContext knows about the community prefix and appends it if needed.

UserContext is automatically bootstrapped by Visualforce, via an inline script like this:

UserContext.initialize({
    "networkId":"0DBJ00000004C9D",
    ...,
    "siteUrlPrefix":"/prefix"
});

And finally: In Sandbox A, this initialization is inlined at the top of the page -- before connection.js is loaded, whereas in Sandbox B, this is inlined in the middle of the page -- after the scripts have already run.

Do you have any idea why this is being rendered differently in the two environments, or how I could control (and fix) the resulting bugs?

  • I have a work-around, but this took me a couple hours to debug so I'm leaving as a resource to future seekers! – Benj Mar 27 '14 at 16:55
4

I was able to work around this issue by putting my script tags at the very bottom of the page, but I'm still baffled by the issue. Would love any insight if you have tips!

    <script>
        // run when page is fully loaded
        jQuery( function($) {
            objDesc = sforce.connection.describeSObject('Custom_Object__c');
        });
    </script>


    // Very last thing on the page
    <script type="text/javascript">
        var __sfdcSessionId = '{!GETSESSIONID()}';
    </script>

    <script src="../../soap/ajax/29.0/connection.js"></script>
</apex:page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.