0

My LWC has a datatable that receives data from an external service and populates that table. I need the email address in the email column to be a link that when clicked opens the contact record for that email address on a separate page. I'm not sure if there are built in functionalities that makes this a straight forward task, I've been looking in the developer guide here: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/reference_lightning_ui_api_record but I can't find a way to do this. My thoughts are to send the email back to and apex class and get the contact ID for that email address but then I'm not sure if this is how it should be done the LWC way and also how would I then open that contact record in a new tab? I have to add that I'm very new to LWC. Thank you for your help!

1
  • I had the honor to appear in the first episode of the new Interchange series hosted by @albarivas. In this video we discussed this topic and Alba goes through details and writes the codes. I hope you enjoy. youtu.be/Oxf4ChjCSG4
    – Bahman.A
    Jul 21 at 5:12
1

First you need to retrieve the contact Ids for the different records using Apex. Then, you need to implement a clickable row in your lightning-datatable, take a look at this recipe. In the recipe it's the account name what I make clickable, but you can adapt it to be the email.

To open the link in a new tab, modify the usage I'm doing of the navigation service by what's suggested in this question.

5
  • Thank you. Are there specific limitations to this? I tried this with Task using the subject, but it just shows empty. I am calling an Apex method with wire however.
    – Andrew L.
    Feb 10 at 22:02
  • Are you passing the subject to the label? github.com/trailheadapps/visualforce-to-lwc/blob/master/… It must be returned by the Apex method too
    – Alba Rivas
    Feb 11 at 9:30
  • Yes, I'm passing the subject as the label and I'm querying for the subject in my Apex method as well. I will test it out with a different object. I'm also on Spring 21.
    – Andrew L.
    Feb 11 at 13:08
  • If you have the code somewhere I can take a look
    – Alba Rivas
    Feb 12 at 12:32
  • Thanks to @albarivas and the Salesforce Developers team. In this video we discuss this topic and Alba explains the details and writes the code for it. Let’s learn together. youtu.be/Oxf4ChjCSG4
    – Bahman.A
    Jul 21 at 5:15

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.