Skip to content

Override the standard "Login to Experience as User" action on the Contact object to open the user's experience in a new browser tab.

Notifications You must be signed in to change notification settings

scojac-github/ExperienceLoginAsUserInNewTab

Repository files navigation

Login to Experience as User in New Tab

This SFDX project provides a solution to override the standard "Login to Experience as User" action on the Contact object to open the user's experience in a new browser tab. A small QOL improvement that delivers a solution for an open IdeaExchange Idea with a whopping 1,600 points.

This component intelligently handles contacts that are members of multiple Experience Cloud sites.

  • If the contact's user is a member of only one active site, it will log them in directly in a new tab.
  • If the contact's user is a member of multiple active sites, a modal window will appear, allowing you to select which site you wish to log in to.

Components

  • ExperienceLoginController: An Apex class that retrieves the login URL or a list of available Experience Cloud sites for a user associated with a Contact.
  • loginToExperienceAsUser: A Lightning Web Component that serves as a screen action, conditionally showing a site selection screen or immediately opening the login URL.
  • Contact.Login_to_Experience_as_User: A Quick Action on the Contact object that invokes the LWC.

Pre-deployment Steps

This solution assumes that the standard Contact object has a relationship to the User object. The Apex code looks for a User record where the ContactId field matches the Contact record. This is a standard relationship in Salesforce.

Deployment

  1. Authorize a Salesforce Org: If you haven't already, authorize your target Salesforce org:

    sfdx auth:web:login --setalias my-dev-org
  2. Deploy the project: Deploy the components to your authorized org:

    sfdx project deploy start --target-org my-dev-org

Post-deployment Steps

  1. Create a Quick Action to the Contact Page Layout:

    • Go to Setup > Object Manager > Contact > Buttons, Links, Actions.
    • Select New Action.
    • Set Action Type to Lightning Web Component
    • Select the c:loginToExperienceAsUser component from the drop down.
    • Give your Action a Label and Name.
    • Next, go to Page Layouts.
    • Select the page layout you want to modify (e.g., "Contact Layout").
    • In the palette, select Mobile & Lightning Actions.
    • Drag the your newly created action from the palette and place it in the "Salesforce Mobile and Lightning Experience Actions" section.
    • Click Save.
  2. Remove the Standard Action (Optional):

    • While editing the page layout, you can remove the original "Login to Experience as User" action to avoid confusion.

Now, when you view a Contact record with an associated Experience Cloud user, you will see the "Login to Experience (New Tab)" action. Clicking it will open the Experience Cloud site in a new tab.

About

Override the standard "Login to Experience as User" action on the Contact object to open the user's experience in a new browser tab.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •