You need to sign in to do that
Don't have an account?

Login as another User in Apex Class
Hi,
In our S-Control, due a particular reason, we first login using another User.
The following is the code to do so
/*****************************************
var usrPwd = null;
var usrName = null;
var currentUrl = sforce.connection.serverUrl;
var results = sforce.connection.query("Select Password__c,Username__c from Administrator__c");
records = results.getArray("records");
if (records.length > 0)
{
admName = records[0].get("Username__c");
admPwd = records[0].get("Password__c");
}
sforce.connection = new sforce.Connection();
var usrName = null;
var currentUrl = sforce.connection.serverUrl;
var results = sforce.connection.query("Select Password__c,Username__c from Administrator__c");
records = results.getArray("records");
if (records.length > 0)
{
admName = records[0].get("Username__c");
admPwd = records[0].get("Password__c");
}
sforce.connection = new sforce.Connection();
try
{
var loginResult = sforce.connection.login(usrName, usrPwd);
}
catch (error)
{
alert("Failed to Authenticate Administrator, + error);
self.close();
}
sforce.connection.serverUrl = currentUrl;
{
var loginResult = sforce.connection.login(usrName, usrPwd);
}
catch (error)
{
alert("Failed to Authenticate Administrator, + error);
self.close();
}
sforce.connection.serverUrl = currentUrl;
*****************************************/
Now I need to migrate the same code to an Apex Class. I can query in an Apex Class but can I login as another User in apex Class in the same way as I am currently doing in S-Control code.
Thanks.
Regards,
Rajesh
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_classes_keywords_sharing.htm
I hope that helps.