You need to sign in to do that
Don't have an account?
How to get logged in User session using AJAX toolkit
Hi,
I'm using AJAS toolkit to call Apex class method from Javascript. The javascript used for calling Apex class method is added in SFDC using Custom Home Page component.
To call Apex class method, it is mandatory to use "sforce.connection.login" method to get sessionId. The login method accepts username, password and token to authenticate and create session. Once authentication is successful, I can use "sforce.apex.execute" method to call Apex class method.
I wish to skip call to "sforce.connection.login" and use logged-in users session so that I don't have to specify User Name, password and token in javascript. Is there any way I can use logged-in Users session in AJAX toolkit. Any help in this regard is appriciated.
Thanks,
Prasad
hi Prasad_more,
try using this:
Hi,
I Too tried to find if the logged in user is valid using the below code
try
{
var
result = sforce.connection.login("myname@myemail.com", "password");
log(
"logged in with session id " + result.sessionId);
}
catch(error) {
if
(error.faultcode.indexOf("INVALID_LOGIN") != -1) {
log(
"check your username and passwd, invalid login");
}
else {
log(error);
}
}
I tried giving my correct userName and password.. but it still went to the catch block.
Please help.
Thanks,
Venkat