I am using the below query to get task and lead details
@AuraEnabled(cacheable = true)
public static List<Task> getRecords(){
List<Task> latestTasks = new List<Task>();
List<Task> taskList = [SELECT Id, CreatedDate, Status, Subject, TYPEOF who
WHEN Contact THEN Name
WHEN Lead THEN Id, Name, Company, Phone, Industry, CreatedDate, State , Country, Postalcode , Street, City
END
FROM Task WHERE Type = 'Call Block' Order by CreatedDate DESC];
system.debug('taskList ' + taskList);
return taskList;
}
In LWC i am using datatable to display lead details
const columns = [
{ label: 'Company Name', fieldName: 'comLink', type: 'url', typeAttributes: { label: { fieldName: 'Company' }, tooltip: 'Go to detail page', target: '_blank' } },
{ label: 'Contact Name', fieldName: 'Name', type: 'text', wrapText: true },
{ label: 'Address', fieldName: 'Address', type: 'text', wrapText: true },
{ label: 'Industry', fieldName: 'Industry', type: 'text', sortable: true, cellAttributes: { alignment: 'left' } },
{ label: 'Date Added', fieldName: 'CreatedDate', type: 'date', typeAttributes: { timeZone: 'UTC', year: 'numeric', month: 'numeric', day: 'numeric' }, sortable: true },
];
I am trying to make Lead Company and Name to be hyperlink to record Id
@wire(getTasks)
tasks({ error, data }) {
if (data) {
let recs = [];
for (let i = 0; i < data.length; i++) {
let task = {};
task.rowNumber = '' + (i + 1);
task.comLink = '/' + data[i].Who.Id;
task.Name = data[i].Who.Name;
task.Address = data[i].Who.City + ' ' + data[i].Who.Street + ' ' + data[i].Who.State + ' ' + data[i].Who.Country + ' ' + data[i].Who.Postalcode;
task.Industry = data[i].Who.Industry;
task.CreatedDate = data[i].CreatedDate;
task = Object.assign(task, data[i]);
recs.push(task);
}
this.records = recs;
this.showTable = true;
} else {
this.error = error;
}
}
But i am getting the url link instead of Company Name. Any idea where it is going wrong.
task.Company = data[i].Who.Company || data[i].Who.Name;
inside your loop?comLink
will give you the Url. In your column definition you say that the label isCompany
, which is not defined at the level ofTask
, and hence my feeling is that defaults to the url itselffieldName
of the column would becomLink
to give the "href" to the link. ThefieldName
of thelabel
of thetypeAttributes
will give you the text to display