JS on vf page gets data from custom object and post on page,after making some changes on page when command button save presses nothing happens. when i took out sforce.connection.sessionId = "{!$Api.Session_ID}"; browser gives an error saying invalid session id and did not get any data for query, still page is displayed, when i press save it will call my methods. Iam not sure why sforce.connection.sessionID not making submit to work, Please help me.

  • can you share entire page code? Also, any specific reason you want to query via javascript, instead of querying in apex?
    – Anshul
    Commented Jun 5, 2015 at 3:48
  • Iam getting all the soql data and creating a dynamic picklist, the picklist values will vary based on the data record types. purpose is to avoid governer limits.
    – user21059
    Commented Jun 5, 2015 at 3:59
  • did you tried to use javascript remoting? It can be a very fast and modular way to access such data.
    – Anshul
    Commented Jun 5, 2015 at 4:07
  • Nope i didnot try JS remoting. what could e the reason command button does not work with APISeSSIon variable?
    – user21059
    Commented Jun 5, 2015 at 4:16

1 Answer 1


Have you considered getting session Id like this:

<apex:includeScript value="/soap/ajax/29.0/connection.js"/>
<apex:includeScript value="/soap/ajax/29.0/apex.js"/>
<script type="text/javascript"> 
var __sfdcSessionId = '{!GETSESSIONID()}';
var oResult = sforce.connection.query(query); 
var oDocuments = oResult.getArray('records'); 
  • No i did this <script type="text/javascript" src="/soap/ajax/24.0/connection.js"></script> <script type="text/javascript" src="/soap/ajax/24.0/apex.js"></script> <script type="text/javascript"> Does it Matters???
    – user21059
    Commented Jun 5, 2015 at 4:13
  • That does not matter but this does -"var __sfdcSessionId = '{!GETSESSIONID()}';". Try this once. Commented Jun 5, 2015 at 4:16
  • Not giving the fault Stirng, but same issue Command Link(save) is not working Any other suggestions?
    – user21059
    Commented Jun 5, 2015 at 4:34
  • Anyone any input, why command button not working with '{!GETSESSIONID()}';
    – user21059
    Commented Jun 5, 2015 at 10:06

You must log in to answer this question.

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