Requirement :- Login Customer community user into Salesforce using Partner WSDL.
I tried solution provided here and it works for customer community users for me using SOAP UI.
But when I used partner wsdl and the c# code shared in Salesforce examples for customer community users, I am getting error : An unexpected error has occurred: INVALID_LOGIN: Invalid username, password, security token; or user locked out.
The same code is working for Salesforce User license users, I am able to get session id for Salesforce user License successfully.
Is there any API login issue for customer community license?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I found the below solution which works for me.
Solution:
- Clone customer community profile with restricted access (enabled API access)
- Create a new Customer community user with a new profile.
- Generate Partner WSDL and shared in C# project with org Id. (for C# project I have used Visual Studio 2013 tool)
- In C# code, Call Login Method in Partner.WSDL with customer community credentials and SFDC Organization Id.
- Retrieve session id and call customize REST/SOAP webservice or we can call query using query() function.
My C# code:
public bool login(){ // Web Reference to the imported Partner WSDL. SforceService partnerBinding = new SforceService(); // To authenticate Self-Service users, we need to set the OrganizationId // in the LoginScopeHeader. string orgId = "Your Org Id"; partnerBinding.LoginScopeHeaderValue = new LoginScopeHeader(); partnerBinding.LoginScopeHeaderValue.organizationId = orgId; String uname = "Customer Community Username"; String pwd = "Customer Community Password"; try { System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)3072; Console.WriteLine("nLogging in...n"); LoginResult lr1 = partnerBinding.login(uname, pwd); // Set the returned service endpoint URL partnerBinding.Url = lr1.serverUrl; // Set the SOAP header with the session ID returned by // the login result. This will be included in all // API calls. partnerBinding.SessionHeaderValue = new SessionHeader(); partnerBinding.SessionHeaderValue.sessionId = lr1.sessionId; Console.WriteLine("lr1.sessionId:- " + lr1.sessionId); } catch (SoapException e) { Console.WriteLine(e.Code); Console.WriteLine(e.Message); } // Return true to indicate that we are logged in, pointed // at the right URL and have our security token in place. return true;
}
Copy and paste above code and run C# application and you will receive sessionid related to customer community user.
C# Code references: LoginScopeHeader
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0