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
jungleeejungleee 

Accessing salesforce data using Ajax toolkit

Hi,

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??

 

<html>
<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', 'https://ap1.salesforce.com/services/Soap/u/26.0');
	j$(document).ready(function(){
		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);
		}
	});
</script>
</html>

 Regards
Sameer

Rahul SharmaRahul Sharma

Sameer,

 

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("myname@myemail.com", "password");

_Prasu__Prasu_
sforce.connection.init('sessionId', 'https://ap1.salesforce.com/services/Soap/u/26.0');

Are you replacing 'sessionId' with its value? 

 

Could you please try following thing?

 

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