0

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?

6
  • Can you try this? salesforce.stackexchange.com/a/201012/19118 Commented Jan 8, 2019 at 13:08
  • Yes, I tried this as well, Profile level- API enabled and pass credentials using soap ui got the successful response. but when I used partner wsdl and the c# code shared in Salesforce examples[developer.salesforce.com/docs/atlas.en-us.api.meta/api/… for customer community users, I am getting error : An unexpected error has occurred: INVALID_LOGIN: Invalid username, password, security token; or user locked out., Commented Jan 8, 2019 at 13:12
  • Is thre IP based login restiction for your community profile user? Commented Jan 8, 2019 at 13:36
  • No IP based restrictions for customer community profile. Login IP range for customer community profile is 0.0.0.0 to 255.255.255.255. Commented Jan 8, 2019 at 13:56
  • 1
    Are you passing the Org Id in your C# code? Checkout the example here LoginScopeHeader
    – Aayush K
    Commented Jan 8, 2019 at 20:25

1 Answer 1

1

I found the below solution which works for me.

Solution:

  1. Clone customer community profile with restricted access (enabled API access)
  2. Create a new Customer community user with a new profile.
  3. Generate Partner WSDL and shared in C# project with org Id. (for C# project I have used Visual Studio 2013 tool)
  4. In C# code, Call Login Method in Partner.WSDL with customer community credentials and SFDC Organization Id.
  5. 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .