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 

No Result from LWC Function Calling

I'm calling getLognotes() on click of button but it's showing nothing in console. I tried to call it from connected callback but when I do that the whole page gets disappear, so I tried button click approach but no go. Even 'Hi' is not getting printed so I think on I'm not even getting inside function.
 
import { LightningElement, track,api, wire } from 'lwc';
import getContentNote from '@salesforce/apex/TBT_SupervisorLog.getContentNote';


export default class tBT_SessionGuideline extends LightningElement {


// connectedCallback(){
//     this._getLogNotes(); // this not working
// }

_getLogNotes(){
    getLogNotes(action).then(res => {
        this.getContentNote = res;
        console.log('hi');
        console.log("content notes result", this.getContentNote);
    }).catch((error)=>{
        console.error("content notes error " ,JSON.stringify(error));
    })
}


*My apex class*
public with sharing class TBT_SupervisorLog {

@AuraEnabled(Cacheable=true)
public static List<ContentNote> getContentNote(){
Set<Id> contactIds = new Set<Id>();
contactIds.add('0030100000ABCD');

Set<Id> contentLinkIds = new Set<Id>();

for(ContentDocumentLink conLink : [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId IN :contactIds]){
    contentLinkIds.add(conLink.ContentDocumentId);
}
List<ContentNote> NoteList = [select id, ContentModifiedDate,  LastModifiedBy.name from ContentNote where Id IN : contentLinkIds ];
    System.debug(NoteList);  
return NoteList;
    }
}
I checked in debug log it's fetching result from class.Please if someone could guide.
 
Best Answer chosen by Abhishek Sharma 527
SubratSubrat (Salesforce Developers) 
Hello Abhishek,

There are some issues with your code , Can you try with below :
 
import { LightningElement, track, api, wire } from 'lwc';
import getContentNote from '@salesforce/apex/TBT_SupervisorLog.getContentNote';

export default class TBT_SessionGuideline extends LightningElement {
    @track getContentNote;

    @wire(getContentNote)
    wiredGetContentNote({ data, error }) {
        if (data) {
            this.getContentNote = data;
            console.log('Content notes result:', this.getContentNote);
        } else if (error) {
            console.error('Content notes error:', error);
        }
    }

    handleButtonClick() {
        getContentNote({ action: 'getLogNotes' })
            .then((result) => {
                console.log('Content notes result:', result);
            })
            .catch((error) => {
                console.error('Content notes error:', error);
            });
    }
}

If the above code helps , please mark this as Best Answer.
Thank you.