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 Answer
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.
-
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. Commented Feb 10, 2021 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 Commented Feb 11, 2021 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. Commented Feb 11, 2021 at 13:08
-
-
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.ACommented Jul 21, 2021 at 5:15