The Sales representatives in my company can log into an user profile by clicking on a custom link in SF classic which is an on click java script and when clicked on that link the representative is redirected to the user's profile by first logging into the company website with the user id from the Account object and the after a small timeout, the rep is redirected to the user's dashboard by the help of an external Id.

The current implementation has a custom link with below java script code and I am trying to implement the same in lightning but since java script doesn't work in lightning.I am unable to figure out how to convert this script into lightning

var wnd = window.open("https://companyUrl/login_as/{!Account.userID}"); 
setTimeout(function() { 
}, 2000);

I cannot write the above functionality in a vf page as the onclick should directly open the url and not be opened in a vf page

  • Hi Keith, welcome to SFSE. Please take a moment to go through how to ask and then edit your question to add more details as what is your current implementation, what are you trying to achieve, what have you done so far, and where are you stuck. Providing these details will help anyone to provide you some direction. – Jayant Das Jun 13 '19 at 20:31
  • What is your question? – Adrian Larson Jun 13 '19 at 21:54
  • Hi Adrian...I need to convert the javascript script to make it work in lightning...below is the code in javascript var wnd = window.open("companyUrl/login_as{!Account.userID}"); setTimeout(function() { wnd.location.replace("companyUrl/dashboards{!Account.externalID}"); }, 2000); – keith Jun 13 '19 at 21:57

Create an Aura Lightning Component that implements force:hasRecordId and force:lightningQuickActionWithoutHeader.

Add a function to the component's javascript controller to get the record id from the component, query the fields you need to construct the URLs, and execute the window functions.

Add an init aura:handler to the component with the action set to call your function.

Include CSS in your component to hide the modal.

Add a Lightning Component Quick Action to the Account object that uses your new component.

Update your Account page layout(s) to use this Quick Action.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.