function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Accessing salesforce data using Ajax toolkit


I have a simple html page in my system. I am trying to access my org details using the ajax toolkit. But I am unable to do so. Any idea how can I access salesforce data in a simple html page in my system using javascript/ jquery??


<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="connection.js"></script>
<script type="text/javascript" src="apex.js"></script>

<script type="text/javascript">
	var j$ = jQuery.noConflict();
	sforce.connection.init('sessionId', '');
		var result = sforce.connection.query("Select Name, Id from User");
		var records = result.getArray("records");
		for (var i=0; i< records.length; i++) {
			var record = records[i];
			console.log(record.Name + " -- " + record.Id);


Rahul SharmaRahul Sharma



If you are trying to access the salesforce data from outside then you need to authenticate before.

Use firebug for debugging when working with javascript or jquery.


Below is ajax toolkit method for connecting to the org.

sforce.connection.login("", "password");

sforce.connection.init('sessionId', '');

Are you replacing 'sessionId' with its value? 


Could you please try following thing?


sforce.connection.init('{!$Api.Session_ID}', '{!$Api.Enterprise_Server_URL_250}');