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

Getting the ajax toolkit to work in a homepage component

Hi guys i am trying to use the ajax toolkit in a homepage component, the problem is i have to login to get a session is there anyway i can do this without logging in. I have created an html area and added the following code:



	<script src="/soap/ajax/16.0/connection.js" type="text/javascript"></script>
	<script type="text/javascript">
		function ShowUser(){
		    //sforce.connection.login("**************8", "********");
			//sforce.connection.sessionId = '{!$Api.Session_ID}';
		    //var user = sforce.connection.getUserInfo();
		window.onload = ShowUser();



But if i do not login it won't work?


You have what you need right there but it's commented out.  Is this not working for you?


//sforce.connection.sessionId = '{!$Api.Session_ID}';

Nope it does not work if i use


sforce.connection.sessionId = '{!$Api.Session_ID}';


it does not work because {!$Api.Session_ID} is null, remember i am doing this in the html area component for home? Can anyone try this out for me thanks


Perhaps you should try grabbing the sessionId directly from the sid cookie.  That might work...




Were you able to resolve this problem?  Please share as I am stuck at exactly the same requirement, i.e. I want the session Id in the home page component.


Thanks in advance