function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhishek Sharma 527Abhishek Sharma 527 

store result in array if id from url is matching with id of result


Hello in my LWC I'm showing all records in page and I want to show only those records which are matching with record id from url.
I tried with @api recordId but that didn't bring result I'm doubtful whether my implementation was correct.
I also tried with event.target.value but that showing error.
import getActiveSessions from '@salesforce/apex/DCController.TBT_getActiveSessions';


_getActiveSessions(){
  getActiveSessions().then(response=>{
    this.dataToDisplay = response
    // for(let i=0;i< this.dataToDisplay.length; i++){
    //     if(this.dataToDisplay[i].id == recordId){           // I tried this way but not getting through it
    //         this.clientData[i] = this.dataToDisplay[i];  
    //     }
    // }
    console.log(response)
  }).catch(error=>{
    console.log(error)
  })
  ;
  console.log('client data '+clientData);
}
//event query running in apex class and that result is coming to LWC by getActiveSessions method

Select Id, Subject, WhatId, WhoId, Who.Name, EndDate, EndDateTime,Start_Date_Time__c , OwnerId, ActivityDate, ActivityDateTime, Facilities__c,Facilities__r.Name, Services__c, Appointment_Status__c, Description, DC_Session_Start_Time__c, DC_Session_End_Time__c, DC_Session_Run_Time__c, DC_Session_Status__c, DC_Session_Last_Start_Time__c, End_Time__c, IsRecurrence, DOSSession__c, What.Name From Event'
can anyone please look into it and guide.

 
SwethaSwetha (Salesforce Developers) 
HI Abhishek,
To show only the record that matches with the record ID from the URL in your LWC, you can use the @wire decorator and getRecord method from the lightning/uiRecordApi module.

Example:
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import FIELD_NAME from '@salesforce/schema/ObjectName.FieldName';

export default class ExampleComponent extends LightningElement {
    @api recordId;

    @wire(getRecord, { recordId: '$recordId', fields: [FIELD_NAME] })
    wiredRecord({ error, data }) {
        if (data) {
            // Use the data to display the record on the page
            console.log(data);
        } else if (error) {
            // Handle the error
            console.log(error);
        }
    }
}

Make sure that the recordId attribute is being passed to your LWC component from the URL correctly. You can check this by adding the following code to your LWC's JS file:
 
import { LightningElement, api } from 'lwc';

export default class ExampleComponent extends LightningElement {
    @api recordId;

    connectedCallback() {
        console.log('Record ID:', this.recordId);
    }
}

If this information helps, please mark the answer as best. Thank you