I’ve read the community posts and the developer docs about getting the running user’s session ID using XXX. But I can’t get it working in my JQuery function below. The function runs SOQL database queries based on input text using JQueryUI autocomplete. It needs to make a connection to Salesforce using the session ID, but it fails, giving an error in the console: Uncaught {faultcode:‘sf:INVALID_SESSION_ID’, faultstring:‘INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session’, detail:{UnexpectedErrorFault:{exceptionCode:‘INVALID_SESSION_ID’, exceptionMessage:‘Invalid Session ID found in SessionHeader: Illegal Session’, }, }, } I’ve tested the function by hard-coding the session ID and it works fine, so I just need to nail this issue. Here’s the code, appreciate any help: skuid.$(function() { //Establish a connection to Salesforce using the //sforce.connection.init(sessionID, ServerURL) function. var template = “{{$Api.Session_Id}}”; //This isn’t working! var sid = skuid.utils.merge(‘global’, template); var server = “https://mmfp.na7.visual.force.com/services/Soap/u/26.0”; //** Will address this hardcoded URL shortly ** sforce.connection.init(sid, server); var jsList; skuid.$(‘#polysearch’).autocomplete({ minLength: 2, //Minimum number of characters user must type before search commences delay: 350, //Delay in milliseconds before the database call is made source: function(request, response) { var st = request.term; jsList =; var query1 = “select Id, Name, ShippingCity, ShippingState, ShippingPostalCode from Account where Name Like '%”+st+“%’ limit 20”; queryResult1 = sforce.connection.query (query1,null); var records1 = queryResult1.getArray(‘records’); for(i=0;i<records1.length;i++){ var obj = { label: records1[i].Name + " " + records1[i].ShippingCity + " " + records1[i].ShippingState + " " + records1[i].ShippingPostalCode , value: records1[i].Id, icon: ‘icon-heart icon-2x icon-fixed-width’ }; jsList.push(obj); } var query2 = “select Id, Name, MobilePhone, Email from Contact where Name Like '%”+st+“%’ limit 20”; queryResult2 = sforce.connection.query (query2,null); var records2 = queryResult2.getArray(‘records’); for(i=0;i<records2.length;i++){ var obj = { label: records2[i].Name + " " + records2[i].MobilePhone + " “+ records2[i].Email, value: records2[i].Id, icon: ‘icon-male icon-2x icon-fixed-width’ }; jsList.push(obj); } var query3 = “select Id, Name, Title, Email from User where Name Like '%”+st+”%’ limit 20"; queryResult3 = sforce.connection.query (query3,null); var records3 = queryResult3.getArray(‘records’); for(i=0;i<records3.length;i++){ var obj = { label: records3[i].Name + " " + records3[i].Title + " “+ records3[i].Email, value: records3[i].Id, icon: ‘icon-user icon-2x icon-fixed-width’ }; jsList.push(obj); } response(jsList); }, select: function( event, ui ) { var uivalue = ui.item.value; window.location.replace(“https://na7.salesforce.com/”+ uivalue); //** Will address this hardcoded URL shortly ** } }).data(“uiAutocomplete”)._renderItem = function (ul, item) { return skuid.$(”
“) .data(“item.autocomplete”, item) .append(” " + item.label + “”) .appendTo(ul); }; });Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.