Reputation: 281
I have used zkSForce in my iOS application to log in to SalesForce. Now I need to access the same data in sandbox environment for the same application.
But when I am trying to log in I am getting the following error.
Error Domain=APIError Code=0 "The operation couldn’t be completed. (APIError error 0.)" UserInfo=0xad3ef20
{faultstring=INVALID_LOGIN: Invalid username, password, security token; or user locked out., faultcode=INVALID_LOGIN}
But when I am trying to connect to production environment I am able to log in successfully. Is there any specific set of instructions to follow to connect to Sandbox using zkSForce? Thanks in advance.
--EDIT--
I am using the following method to log in.
[SFAccountManager setLoginHost:@"test.salesforce.com"];
[SFAccountManager setClientId:CLIENTID];
[SFAccountManager setRedirectUri:REDIRECTURI];
[SFAccountManager setCurrentAccountIdentifier:USERNAME];
[SFAccountManager sharedInstance].coordinator.credentials.instanceUrl=[NSURL URLWithString:@"https://test.salesfoce.com"];
[[FDCServerSwitchboard switchboard] loginWithUsername:username password:passwordToken target:self selector:@selector(loginResult:error:)];
and the result is handled by the following method
- (void)loginResult:(ZKLoginResult *)result error:(NSError *)error{
if (result && !error){
[[SFAccountManager sharedInstance].coordinator.credentials setAccessToken:nil];
[SFAccountManager sharedInstance].coordinator.credentials.accessToken = result.sessionId;
}
else if (error){
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Login failed" message:@"Error" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[myAlertView show];
}
}
Upvotes: 0
Views: 231
Reputation: 281
I am not sure if this is the perfect solution but adding the following line worked for me.
[[FDCServerSwitchboard switchboard] setApiUrlFromOAuthInstanceUrl:LOGINHOSTURL];
where LOGINHOSTURL is you host URL.
Thanks @superfell for giving me the hint
Upvotes: 1
Reputation: 19040
Login requests for Sandbox need to goto a different endpoint than the default one for production, so you need to call setLoginProtocolAndHost: on the client object before calling login, e.g.
ZKSforceClient *c = [[ZKSforceClient alloc] init];
[c setLoginProtocolAndHost:@"https://test.salesforce.com"];
[c login:self.username password:self.password];
...
Upvotes: 1