You are here:
Configure a Login Flow at the Primary Salesforce Org
To synchronize a user's identity between B2C Commerce and the Salesforce org IdP, configure a login flow at the primary Salesforce org. When a user signs in to the Salesforce IdP org, this flow handles the synchronization.
- Sign in to the primary Salesforce org acting as the IdP.
-
Create the Login Flow invocable action.
-
At the top of the page, click
and select Setup.
- In the Quick Find box, enter and select Apex Classes.
- Click New.
-
Copy this code and paste it into the Apex Class editor.
/** * Invocable action for the login flow to synchronize the merchant's * identity between the Commerce Cloud and the Core Identity Provider. */ public class CommerceIdentitySyncAction { @InvocableMethod( label='Sync Commerce Identity' description='Establishes the mapping between the logged-in core user and the ECOM user.' category='Identity' ) public static List<ActionResult> execute() { List<ActionResult> results = new List<ActionResult>(); ActionResult result = new ActionResult(); try { // Invoke the system identity synchronization logic Auth.CommerceIdentitySynchronizationAction.UserSynchronizationResult syncStatus = Auth.CommerceIdentitySynchronizationAction.establishUserSynchronization(); if (syncStatus != null) { result.isSuccess = syncStatus.isSuccess; result.errorMessage = syncStatus.errorMessage; } } catch (Exception ex) { // Catching any unexpected issues to prevent the Login Flow from breaking result.isSuccess = false; result.errorMessage = 'An unexpected error occurred during identity sync: ' + ex.getMessage(); } results.add(result); return results; } /** * Captures the status of the synchronization for use in Flow decision elements. */ public class ActionResult { @InvocableVariable(label='Is Success' description='True if the identity mapping was created successfully.') public Boolean isSuccess; @InvocableVariable(label='Error Message' description='The reason the synchronization failed, if applicable.') public String errorMessage; } } - Click Save.
-
At the top of the page, click
-
Create and assign the login flow in Salesforce IdP org.
- In the Quick Find box, find and select Flows.
- Click New, and then select Screen Flow.
- Between Screen Flow Start and End, click the + button, and then select Action.
- Search for the action Sync Commerce Identity.
- Select the action and provide a Label and API Name.
- Click Save.
- Click Activate, and then exit Flow Builder.
- In the Quick Find box, enter and select Login Flows.
-
Click New, and enter the field values in the table.
Field Value Type Flow Flow Select the flow that you created. User License Salesforce Profile Standard User - Save your changes.

