I have created LWC, which is having controller to fetch task records from apex controller. but it is again giving me same error "Object Task is not supported in UI API". can any one please let me now what is wrong in this code.
js file:
import { LightningElement, api, wire, track } from 'lwc';
import { getSObjectValue } from '@salesforce/apex';
import GetTaskRecords from '@salesforce/apex/FetchTaskLWCController.GetTaskRecords';
import task_Object from '@salesforce/schema/Task';
import Task_Assigned_To from '@salesforce/schema/Task.OwnerId';
import Task_Status from '@salesforce/schema/Task.Status';
import Task_Priority from '@salesforce/schema/Task.Priority';
import Task_Due_Date from '@salesforce/schema/Task.ActivityDate';
import Task_Type from '@salesforce/schema/Task.Type';
import Task_Related_to_Account from '@salesforce/schema/Task.WhatId';
import Task_Subject from '@salesforce/schema/Task.Subject';
import Task_Comments from '@salesforce/schema/Task.Description';
export default class ApexWireMethodToFunction extends LightningElement {
@api TaskRecord;
@api recordId;
@track tasks;
@track error;
taskObject = task_Object;
@wire(GetTaskRecords, {Id: '$TaskRecord'})
task;
get assignedto() {
return this.task.data ? getSObjectValue(this.task.data, Task_Assigned_To) : '';
}
get status() {
return this.task.data ? getSObjectValue(this.task.data, Task_Status) : '';
}
get priority() {
return this.task.data ? getSObjectValue(this.task.data, Task_Priority) : '';
}
get duedate() {
return this.task.data ? getSObjectValue(this.task.data, Task_Due_Date) : '';
}
get type() {
return this.task.data ? getSObjectValue(this.task.data, Task_Type) : '';
}
get relatedtoaccount() {
return this.task.data ? getSObjectValue(this.task.data, Task_Related_to_Account) : '';
}
get subject() {
return this.task.data ? getSObjectValue(this.task.data, Task_Subject) : '';
}
get comments() {
return this.task.data ? getSObjectValue(this.task.data, Task_Comments) : '';
}
wiredTasks({ error, data })
{
if (data)
{
this.tasks = data;
this.error = undefined;
} else if (error)
{
this.error = error;
this.tasks = undefined;
}
}
}
html file:
<template>
<lightning-card>
<!-- Opportunity -->
<!-- Display -->
<template if:true={TaskRecord}>
<lightning-record-form
record-id={TaskRecord}
object-api-name={taskObject}
>
<!-- Messages -->
<lightning-messages></lightning-messages>
<div class="slds-p-bottom_large slds-p-left_large">
<br/>
<!-- Fields -->
<lightning-accordion active-section-name="A">
<lightning-accordion-section name="A" label="Task Details">
<div class="slds-grid" style="color:rgb(15, 15, 15); font-size:13px">
<div class="slds-col slds-size_1-of-2">
<div class=" acc slds-list_horizontal slds-border_bottom">
<label>Subject</label>
{subject}
</div>
<div class=" acc slds-list_horizontal slds-border_bottom">
<label>Status</label>
{status}
</div>
<div class=" acc slds-list_horizontal slds-border_bottom">
<label>Related To Account</label>
{relatedtoaccount}
</div>
<div class="acc slds-border_bottom slds-list_horizontal">
<label>Priority</label>
{priority}
</div>
<div class="formfield slds-list_horizontal slds-border_bottom">
<label>Assigned To</label>
<div class="a11">{assignedto}</div>
</div>
</div>
<div class="slds-col slds-size_2-of-2">
<div class="slds-col slds-size_1-of-2">
<div class="formfield slds-border_bottom slds-list_horizontal">
<label>Due Date</label>
{duedate}
</div>
<div class="formfield slds-border_bottom slds-list_horizontal">
<label>Type</label>
{type}
</div>
<div class="formfield slds-border_bottom slds-list_horizontal">
<label>Comments</label>
{comments}
</div>
</div>
</div>
</div>
</lightning-accordion-section>
</lightning-accordion>
</div>
<br/>
</lightning-record-form>
</template>
</lightning-card>
js-meta.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="partnerOpportunityRecordRead">
<apiVersion>47.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>partner Task Record Read LWC</masterLabel>
<targets>
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
</targets>
<targetConfigs>
<targetConfig targets="lightningCommunity__Default">
<property name="TaskRecord" type="String" default="Record_ID"/>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>
Controller :
public with sharing class FetchTaskLWCController
{
@AuraEnabled(cacheable=true)
public static List<Task> GetTaskRecords()
{
return [SELECT Id, OwnerId, Status, Priority, ActivityDate, Type, WhatId, Subject, Description FROM Task];
}
}
As task and event are unsupported objects in UI API, so took apex controller approach.