Link to a record detail page from a Lightning Component

  • I have a Lightning Component in my Home page that filter a list of Opportunities. On the title I have a link to the list on the Opportunity tab that works perfectly. enter image description here This is the code.

    <a href="/one/one.app?#/sObject/Opportunity/list?filterName=00B28000000zx7MEAQ" target="_blank" class="slds-type-focus">
    <span class="slds-section__title">My Policies due to Renewal</span></a> 
    

    I tried to create a similar link on the Opportunity Name to open the record detail page with no success. My code is:

    <a href="{!'/one/one.app?#/sObject/'+ opp.Id}" target="_blank">{! opp.Name }</a>

    I got the error message

    "This page isn't available in Salesforce Lightning Experience or Salesforce1". The address in the URL is : /one/one.app?#/sObject/006280000074WXdAAM and it should be : /one/one.app?#/sObject/006280000074WXdAAM/view?t=1478147610998

    How can I get the view part?

  • Praveen

    Praveen Correct answer

    5 years ago

    Just append view text to the end of href of the anchor tag.

     <a href="{!'/one/one.app?#/sObject/'+ opp.Id + '/view'}" target="_blank">{! opp.Name }</a>
    

    I would like to use as target "_blank", but it generates error to me. There is any alternative option to refresh the page and not to open a new tab?

    Can you open a new question and link to this answer with details of error you are getting?

    @Praveen Do you have any idea about link to a record edit page? I tried appending /edit. It works but when clicked on save it does not navigate to view instead to comes back to edit page.

    @snehakem Somewhere internally the return url is sent behind the scene.At the moment I don't have a solution for your problem.

    Thanks for you response @Praveen. I will figure out some other way.

    WARNING SUMMER'18: this answer still working but not behaving nice anymore, because it reloads the entire page and navigation is slowed down.

    reading this ans: can we avoid that hardcoding url :{!'/one/one.app?#/sObject/'+ opp.Id + '/view'}.any alternate way

    @AnnappaPH To avoid hardcoding the parts of the url, you need to use attach `onclick` to the tag and in the js code use `lightning:navigate` methods for redirection.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM