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
TheRotnelsonTheRotnelson 

How to determine correct account to associate to user provisioned trough social login for communities

Hi,
I am looking for what are best practice or common strategies used when you have a B2B communites where users can login with social sign in?
To which account should communites user that are provisioned in the apex registration handler be associated with? E.g if they are signing in with Google or Facebook, how would you associate them with the correct Account.

What are the best practices and common practices here?
Best Answer chosen by TheRotnelson
Chris Gary CloudPerformerChris Gary CloudPerformer
First of all,
Best question I've seen all day.....😀
It seems like Communities is geared more toward B2C rather than B2B with the Social login options.... I can tell you from experience that it is almost impossible to find or create the Contact record associated with the correct Business Account if they are using social logins because 99% of the time, their Google information (I'm going to use Google as the example here) is in no way associated to their business email or business ANYTHING for that matter.
I am a developer with an SI (Salesforce Implementation) Partnered company, so I can tell you some examples of how we handled it for different clients.

Honestly, many clients I've seen in the SF ecosystem using communities don't go with the Social login component for B2B communities because you can't really keep your Contact and User record association can be tricky to find and maintain.  The majority of the implementations I've done are B2C, so our client doesn't care what account a contact record is associated with. We've created a single 'Online Account' record for them, and in the registration handler, tied the creation of the contact/user record to that.  For the Contact record (in google's case, we sometimes record the 'sub' attribute value on the contact record - so that we avoid 're-creation' of contact records in the Registration Handler). For B2B Accounts we've done a few different things.
For those Accounts where their domain is hosted with Google - google does provide an 'hd' - hosted domain value in the UserInfo if the user is associated with a Google Business Account. The 'hd' value is actually the company domain 'mycompany.com', so sometimes you will get success looking for an account with that domain - if your data is super clean - AND the clients' customers are Google Domain hosted..... I believe facebook has a similar concept if the Facebook account is tied to a Business Facebook account.
We have much more success with LinkedIn Social Logins. Because we can request the work history scope - I've done some fun things with Parsing that to compare against Account SF records and finding the right Account. 
In all of the cases, however, we have usually created a 'catch-all' account to use for Social Registrations, and when the Contact is created attached to that catch-all account, here is where we have gotten creative....
We've auto-created tasks to assign to SF users to manually review and re-associate, we've sent auto-emails asking to complete the registration - and then forwarded them to a wizard to provide enough information to 're-associate' the contact to the right account - we've auto-popped live agent on the home page to direct them to a rep that corrects wrong account associations. One of the more interesting implementations is that we actually created Accounts for them, and upon login, walked them through a 'finish your account' wizard that associated this 'Personal Account' to a parent business account in a hierarchical fashion and also created 'Contact Roles' on both accounts so that the contact would have an association and proper role with each account. 
One thing Salesforce introduced to take these solutions out of code and into the more point-click has been Login-Flows (https://developer.salesforce.com/page/Login-Flows). As a developer, I must say, I do like it - but I have only used it once with Social logins, and that was to get more user info upon initial sign-in.  Can't wait to use it for more complex stuff to see how it holds up.
In the end, it wasn't about getting the Account/Contact association right upon login, but instead, having a structured process to re-associate the records properly - whether or not that process is automated/self-service.
The fun part is when you are going to ask about multiple social logins for a single User....

Happy Travels!
P.S. Please don't forget to mark a comment as 'Best Answer' (whether or not its mine). It helps the community!

All Answers

Chris Gary CloudPerformerChris Gary CloudPerformer
First of all,
Best question I've seen all day.....😀
It seems like Communities is geared more toward B2C rather than B2B with the Social login options.... I can tell you from experience that it is almost impossible to find or create the Contact record associated with the correct Business Account if they are using social logins because 99% of the time, their Google information (I'm going to use Google as the example here) is in no way associated to their business email or business ANYTHING for that matter.
I am a developer with an SI (Salesforce Implementation) Partnered company, so I can tell you some examples of how we handled it for different clients.

Honestly, many clients I've seen in the SF ecosystem using communities don't go with the Social login component for B2B communities because you can't really keep your Contact and User record association can be tricky to find and maintain.  The majority of the implementations I've done are B2C, so our client doesn't care what account a contact record is associated with. We've created a single 'Online Account' record for them, and in the registration handler, tied the creation of the contact/user record to that.  For the Contact record (in google's case, we sometimes record the 'sub' attribute value on the contact record - so that we avoid 're-creation' of contact records in the Registration Handler). For B2B Accounts we've done a few different things.
For those Accounts where their domain is hosted with Google - google does provide an 'hd' - hosted domain value in the UserInfo if the user is associated with a Google Business Account. The 'hd' value is actually the company domain 'mycompany.com', so sometimes you will get success looking for an account with that domain - if your data is super clean - AND the clients' customers are Google Domain hosted..... I believe facebook has a similar concept if the Facebook account is tied to a Business Facebook account.
We have much more success with LinkedIn Social Logins. Because we can request the work history scope - I've done some fun things with Parsing that to compare against Account SF records and finding the right Account. 
In all of the cases, however, we have usually created a 'catch-all' account to use for Social Registrations, and when the Contact is created attached to that catch-all account, here is where we have gotten creative....
We've auto-created tasks to assign to SF users to manually review and re-associate, we've sent auto-emails asking to complete the registration - and then forwarded them to a wizard to provide enough information to 're-associate' the contact to the right account - we've auto-popped live agent on the home page to direct them to a rep that corrects wrong account associations. One of the more interesting implementations is that we actually created Accounts for them, and upon login, walked them through a 'finish your account' wizard that associated this 'Personal Account' to a parent business account in a hierarchical fashion and also created 'Contact Roles' on both accounts so that the contact would have an association and proper role with each account. 
One thing Salesforce introduced to take these solutions out of code and into the more point-click has been Login-Flows (https://developer.salesforce.com/page/Login-Flows). As a developer, I must say, I do like it - but I have only used it once with Social logins, and that was to get more user info upon initial sign-in.  Can't wait to use it for more complex stuff to see how it holds up.
In the end, it wasn't about getting the Account/Contact association right upon login, but instead, having a structured process to re-associate the records properly - whether or not that process is automated/self-service.
The fun part is when you are going to ask about multiple social logins for a single User....

Happy Travels!
P.S. Please don't forget to mark a comment as 'Best Answer' (whether or not its mine). It helps the community!
This was selected as the best answer
TheRotnelsonTheRotnelson
Thanks Chris!
Fantatsic! Very informal and useful answer. 
I think levering login flows could be the way to go :)