Whenever we do some customization or VF page development for a specific profile users, there will be a need to test the development by logging in with that profile.
By doing so, we can track or identify the issues making our development totally error free.
To do this, we need to search for a user and click "Login" button on user detail page every time assuming if the access is already granted or if the setting Administrators Can Log in as Any User is enabled.
This post guides you an easiest way of handling the process, by logging in as another user directly from the sidebar link and if the access is granted.
Create a Custom Link by following the below path,
Your Name ➤ App Setup ➤ Home ➤ Custom Links ➤ New
Label : Contract Operations
Name : Contract_Operations
Behaviour : Execute Javascript
Paste the below code,
{!REQUIRESCRIPT("/soap/ajax/18.0/connection.js")} sforce.connection.query("SELECT Id,Name,Profile.Name FROM User where Profile.Name=\'Contract Operations\' LIMIT 1",{onSuccess: handleSuccess,onFailure: handleFailure}); function handleSuccess(queryresult) { try { records = queryresult.getArray("records"); var user = sforce.connection.getUserInfo(); window.location.href = '/servlet/servlet.su oid='+user.organizationId+'&suorgadminid='+records[0].Id.substring(0,15)+ '&retURL=%2Fhome%2Fhome.jsp'+'&targetURL=%2Fhome%2Fhome.jsp'; } catch(error) { alert(error); } } function handleFailure(error) { alert(error); }
You can have as may have links created for different profiles also.
Create a Custom Component using below path,
Your Name ➤ App Setup ➤ Home ➤ Home Page Components ➤ New
Name : Login As.....
Type : Links
- Include the Custom Link that was created previously.
- Finally include this Custom Component in the System Administrator Home Page Layout under Narrow(Left) column.