Newer Version Available
HeadlessSelfRegistrationHandler Interface
Namespace
Usage
The Headless Registration Flow allows you to control user registration experience in a third-party app while using Salesforce to authenticate users and manage their data access. When you set up this flow, add users in the class that is implementing the Auth.HeadlessSelfRegistrationHandler interface. This class runs after the user verifies their identity. For a detailed explanation of headless registration, see Headless Registration Flow for Private Clients or Headless Registration Flow for Public Clients, depending on your app type.
HeadlessSelfRegistrationHandler Methods
createUser(profileId, data, customUserDataMap, experienceId, password)
Signature
public User createUser(Id profileId, Auth.UserData data, String customUserDataMap, String experienceId, String password)
Parameters
- profileId
- Type: Id
- The ID of the profile that is assigned to new users.
- data
- Type: Auth.UserData
- A class that stores information about the user, such as their name and locale.
- customUserDataMap
- Type: String
- A string representation of a JSON object containing custom user information passed in during registration. We recommend that you deserialize this string into the equivalent Apex class structure. Determine what custom information to collect when you build your app’s registration experience.
- experienceId
- Type: String
- The Experience Cloud site ID.
- password
- Type: String
- The user password.
Return Value
Type: User
HeadlessSelfRegistrationHandler Example Implementation
1global class ExampleHeadlessReg implements Auth.HeadlessSelfRegistrationHandler {
2
3 global User createUser(Id profileId, Auth.UserData data, String customUserDataMap, String experienceId, String password){
4 User u = new User();
5 u.ProfileId = profileId;
6
7 u = handleUnsetRequiredFields(u);
8 u.email = data.email;
9 Account a;
10 List<Account> accounts = [SELECT Id FROM account WHERE name=:social_account];
11 if(accounts.isEmpty())
12 {
13 a = new Account(name = social_account);
14 insert(a);
15 }else
16 a = accounts[0];
17 generateContact(u, a.Id);
18 u.languagelocalekey = UserInfo.getLocale();
19 u.localesidkey = UserInfo.getLocale();
20 u.emailEncodingKey = 'UTF-8';
21 u.timeZoneSidKey = UserInfo.getTimezone().getID();
22 return u;
23 }
24
25 private User handleUnsetRequiredFields(User u) {
26 return u;
27 }
28
29 // Method to construct a contact for a user
30 private void generateContact(User u, Id accountId) {
31 // Add logic here to build your own contact for the user
32 Contact c = new Contact();
33 c.accountId = accountId;
34 c.firstName = u.firstName;
35 c.lastName = u.lastName;
36 insert(c);
37 u.contactId = c.Id;
38
39 }
40
41 // Default implementation to try to provide uniqueness
42 private String generateAlias() {
43 String timeString = String.valueOf(CURRENT_TIME);
44 return timeString.substring(timeString.length() - 8);
45 }
46}