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
AmanAman 

Login Error through Ajax Toolkit

<apex:page >
<html>
<head>
<title> Ajax ToolKit </title>
 <script src="/soap/ajax/22.0/connection.js" type="text/javascript"></script>
  <script language="JavaScript">
  function check()
  {
 
 try{
    var result = sforce.connection.login("a@abc.com", "password");
    alert("result");
    alert("you are loged in");
    
    log("logged in with session id " + result.sessionId);
  }

catch(error) {


  alert("Wrong user name and password");

    if (error.faultcode.indexOf("INVALID_LOGIN") != -1) {
   // alert(error);
      sforce.debug.log("check your username and passwd, invalid login");
    } else {
      sforce.debug.log(error);
    }
  }
   }
  </script>
  
</head>
  <body>
  <apex:form >
  <apex:commandButton onclick="check();" value="Click"/>
</apex:form>
</body>
</html>
</apex:page>

 

// When I run this code it wil not respond me correctly either i entered correct credentials in mentioned red line above.

It took me at the alert message " Wrone Username and Password"

Please help me. If there is any error in my code let me.

Rahul SharmaRahul Sharma

Had u Alerted the error in catch:

 

catch(error) {


  alert("Wrong user name and password " + error);

 I think Log is not defined here.. Instead of using log, alert it:

 

<apex:page >
<html>
<head>
<title> Ajax ToolKit </title>
 <script src="/soap/ajax/22.0/connection.js" type="text/javascript"></script>
  <script language="JavaScript">
  function check()
  {
 
 try{
    var result = sforce.connection.login("a@abc.com", "password");
    alert("result");
    alert("you are loged in");
    
    alert("logged in with session id " + result.sessionId);
  }

catch(error) {


  alert("Wrong user name and password");

    if (error.faultcode.indexOf("INVALID_LOGIN") != -1) {
   // alert(error);
      sforce.debug.log("check your username and passwd, invalid login");
    } else {
      sforce.debug.log(error);
    }
  }
   }
  </script>
  
</head>
  <body>
  <apex:form >
  <apex:commandButton onclick="check();" value="Click"/>
</apex:form>
</body>
</html>
</apex:page>

 Hope it helps

Venkat@12Venkat@12

 

Hi,

 

I Tried the above code using the correct credentials, but ir displayed an alert message (Wrong username and password).

 

An Ajax tool kit Shell has poppedup allowing us to enter some text.. what is it used for.

 

Thanks,

Venkat