I have a controller with a apex method which takes a user id. This controller is used in a LWC component. Here is where I am trying to call the apex method via a wire method.
This is done in a Experience Site where I have placed the LWC component which is the only component on the page.
The user Id is taken using standard salesforce functionality and the method is imported.
import USER_ID from "@salesforce/user/Id";
import updateStatusOpen from '@salesforce/apex/UpdateFormRequestStatusController.updateFormRequestStatusOpened';
The controller method:
@AuraEnabled(cacheable=true)
public static void updateFormRequestStatusOpened(Id userId) {
System.debug('Here ' + userId);
System.debug('here ' + userinfo.getProfileid());
System.debug('here ' + UserInfo.getUserId());
}
Right now the console debugs are 'In Lwc' amd 'outside' its like it just skips calling the method.
@wire(updateStatusOpen, { userId: '$userId' })
wiredCustomObjects({ error, data }) {
console.log('In LWC');
if (data) {
console.log('Success');
} else if (error) {
console.error('Error loading custom objects', error);
}
console.log('outsides');
}
There are no logs in the Developer Console which is why I think the method is not being called at all. I have also tried running the method imperatively and no error logs are displayed. It also calls the wire adapter twice.
Full code
import { LightningElement, wire } from 'lwc'; import USER_ID from "@salesforce/user/Id"; import updateStatusOpen from '@salesforce/apex/UpdateFormRequestStatusController.updateFormRequestStatusOpened';
export default class ExperienceFormRequestStatusOpened extends LightningElement {
userId = USER_ID;
wiredCustomObjects;
connectedCallback() {
console.log('connected callback');
updateStatusOpen({userId: this.userId })
.then(result => {
console.log('inside connected callback ' + this.userId);
console.log(result);
})
.catch(error => {
console.error('Error fetching data: ', error);
});
}
}