Skip to main content
Mention lightning__RecordPage
Source Link
Joe Flowers
  • 686
  • 4
  • 16

You need to make sure your configuration file enables you to put the component on a record detail lightning app page by adding the lightning__RecordPage target in your configuration file for the component.

<targets>
    <target>lightning__RecordPage</target>
</targets>

Specifically here's their Apex class example

Specifically here's their Apex class example

You need to make sure your configuration file enables you to put the component on a record detail lightning app page by adding the lightning__RecordPage target in your configuration file for the component.

<targets>
    <target>lightning__RecordPage</target>
</targets>

Specifically here's their Apex class example

Source Link
Joe Flowers
  • 686
  • 4
  • 16

You have a line that says

@wire(fetchTasks) parameters;

You need to do more than that. Have a look at the "Wire an Apex Method with a Dynamic Parameter" example in the LWC docs

https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.apex

In their example they're using a phrase 'searchKey' that the user types in, whereas you're going to be using the recordId that is automatically injected into your @api recordID property as long as you're on a record detail page.

Specifically here's their Apex class example

ContactController.cls

public with sharing class ContactController {
        @AuraEnabled(cacheable=true)
        public static List<Contact> findContacts(String searchKey) {
            String key = '%' + searchKey + '%';
            return [SELECT Id, Name, Title, Phone, Email, Picture__c FROM Contact WHERE Name LIKE :key AND Picture__c != null LIMIT 10];
        }
    }

As well as their JS example

apexWireMethodWithParams.js

import { LightningElement, track, wire } from 'lwc';
import findContacts from '@salesforce/apex/ContactController.findContacts';

/** The delay used when debouncing event handlers before invoking Apex. */
const DELAY = 300;

export default class ApexWireMethodWithParams extends LightningElement {
    @track searchKey = '';

    @wire(findContacts, { searchKey: '$searchKey' })
    contacts;

    handleKeyChange(event) {
        // Debouncing this method: Do not update the reactive property as long as this function is
        // being called within a delay of DELAY. This is to avoid a very large number of Apex method calls.
        window.clearTimeout(this.delayTimeout);
        const searchKey = event.target.value;
        this.delayTimeout = setTimeout(() => {
            this.searchKey = searchKey;
        }, DELAY);
    }
}

And here is their HTML template

apexWireMethodWithParams.html

<template>
    <lightning-card title="ApexWireMethodWithParams" icon-name="custom:custom63">
        <div class="slds-m-around_medium">
            <lightning-input type="search" onchange={handleKeyChange} class="slds-m-bottom_small" label="Search" value={searchKey}></lightning-input>
            <template if:true={contacts.data}>
                <template for:each={contacts.data} for:item="contact">
                    <p key={contact.Id}>{contact.Name}</p>
                </template>
            </template>
            <template if:true={contacts.error}>
                <c-error-panel errors={contacts.error}></c-error-panel>
            </template>
        </div>
    </lightning-card>
</template>