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
Kevin Yao 4Kevin Yao 4 

Login to another org using LWC/Apex/Aura

I was wondering if it was possible to login to different salesforce environments (Sandboxes, scratch orgs, production env, etc) using either Apex/LWC/Aura. For example, I have a list of credential records, with the username and password, and I would like to have a login button that creates a separate tab that can automatically redirect to that specific instance and login.

Currently, if a user wants to login to a particular instance, they have to either go to test.salesforce.com or login.salesforce.com (depending on if it's a sandbox or production) manually, then copy the password and username in. The ideal situation is to have a login button that can do this automatically from the record page where the username and password is located.

I've been trying to do some research and haven't been able to really find an ideal solution.
SwethaSwetha (Salesforce Developers) 
Hi Kevin,
You might want to explore the option of Environment Hub

https://developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/packagingGuide/environment_hub_intro.htm

https://salesforce.stackexchange.com/questions/221772/how-can-i-get-access-of-environment-hub

The Environment Hub lets you connect, create, view, and log in to Salesforce orgs from one location. If your company has multiple environments for development, testing, and trials, the Environment Hub lets you streamline your approach to org management.

If this information helps, please mark the answer as best. Thank you
Kevin Yao 4Kevin Yao 4
Thanks for the response - I've looked into the Environment Hub and while it's similar to what I'm trying to accomplish, it doesn't seem to be able login using specific login combinations (username/password). I think previously before it was patched out, there was an option to use the URL login to pass in the username and password, but that's no longer an option. Also - we also have a lot of scratch orgs/sandboxes and production orgs that we want to manage, and it doesn't seem that you can login to scratch orgs from Enviornment Hub (though I may be mistaken)
SwethaSwetha (Salesforce Developers) 
I'll check and confirm if scratch orgs are available with Enviornment Hub.Also,I'll see if I can find any app exchange package that can help with what you are looking for.

Thanks