You need to sign in to do that
Don't have an account?
Display data in Column using LWC
I am trying to create a view to show activity information. However the below code is not displaying any information, only header is showing. Please help.
HTML Component : <template> <lightning-card class="slds-text-title_bold" title = "Activity Information"> <div class="slds-p-around_medium lgc-bg" style="height: 300px;"> <lightning-datatable key-field="id" data={data} columns={columns}> </lightning-datatable> </div> </lightning-card> </template>
JS File: import { LightningElement,api,wire,track} from 'lwc'; import ActivitySearchController from '@salesforce/apex/ActivityLeadPage.ActivitySearchController' const columns = [ { label: 'Subject', fieldName: 'Subject' }, { label: 'Due Date', fieldName: 'ActivityDate' }, { label: 'Status', fieldName: 'Status' }, ]; export default class ActivityLeadPageComponent extends LightningElement { @api recordId; @track data = []; @track columns = columns; @wire(ActivitySearchController, { currentID: '$recordID'}) TaskList; }
Controller : public class ActivityLeadPage{ @AuraEnabled(cacheable=true) public static List<Task> ActivitySearchController(String currentID){ List<Task> TaskList = new List<Task>(); Map<Id,Lead> leadMap = new Map<Id,Lead>(); if(currentID.startsWith('00Q')){ try{ List <Lead> leadList = [SELECT id, Email FROM Lead WHERE ID=:currentId]; String ldEmail = leadList[0].Email; Set<String> emailIds = new Set<string>(); if(ldEmail!=null){ emailIds.add(ldEmail); } TaskList = getTaskList(emailIds); } catch(Exception e){ system.debug('getlinenumber-->'+ e.getMessage() +' line '+ e.getLineNumber()); } } return TaskList; } public static List<Task> getTaskList (Set<String> emailIds) { Map<Id,Lead> leadMap = new Map<Id,Lead>(); leadMap = new Map<Id,Lead>([SELECT id, Email FROM Lead Where Email IN:emailIds]); Set<Id> leadID = new Set<Id>(); for(Lead lE : leadMap.values()){ leadID.add(lE.id); } List<Task> TaskList = [Select id, Subject, Description, who.Type, What.Type, Priority, Status, ActivityDate,CreatedDate, LastModifiedDate FROM Task WHERE whoId IN:leadID ORDER BY createddate DESC LIMIT 20]; if(TaskList.size() == 0){ Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No Tasks to Display')); } return TaskList; } }
refer this link https://www.codengine.in/2019/08/salesforce-lightning-datatable-example-with-lwc-lightning-web-component.html
it would be like
Try this and let me know if any issues
--
Naveen K N
All Answers
Access to the record ID.: '$recordId'
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.use_record_context
Javascript is case sensitive but not Apex.
Many thanks for correction, however the table is still showing without values. The record has 3 tasks.
refer this link https://www.codengine.in/2019/08/salesforce-lightning-datatable-example-with-lwc-lightning-web-component.html
it would be like
Try this and let me know if any issues
--
Naveen K N
That's worked. Thank you so much.
I would like to add one more column to the table i.e., Object. This column will have value based on the whoID and WhatID. For eg: if task whoID beings with 00Q then the value should be Lead, similarly if the task whoID beings with 001 then the value will be Account and if whatID being with 006 then value will be Opportunity. Appreciate your guidance.
https://www.codekiat.com/2019/08/salesforce-lightning-datatable-example-with-lwc-lightning-web-component.html