DISCLAIMER : I know there are better ways to get the current User Id, I am just writing this up as example to illustrate the issue I am facing.
Let's say I have two apex methods that are @AuraEnabled (cacheable=true):
@AuraEnabled (cacheable=true)
public static id getUserId() {
return UserInfo.getUserId();
}
@AuraEnabled (cacheable=true)
public static List<Task> getTasksForUser(Id userId) {
List<Task> returnValue = new List<Task>();
for (Task task : [SELECT Id, WhoId, WhatId, Subject, ActivityDate, Priority, Status FROM Task WHERE OwnerId = : userId]) {
returnValue.add(task);
}
return returnValue;
}
and I also have a Lightning Web Component which uses the @wire notation to wire the results of these methods to properties:
@wire(getUserId, {}) myId;
@wire(getTasksForUser, { userId: '$myFormattedId' }) myTasks;
get myFormattedId () {
if (this.myId && this.myId.data) {
return this.myId.data;
}
return undefined;
}
I am having a difficult time getting the myTasks
variable to be populated correctly.
It seems as though the call to getTasksForUser
gets cached as an empty list, then the myId
variable gets populated, and getTasksForUser
is called again, but it never makes it to the server, even though the input variable has changed since its' original call.
This did not seem to be the case as of a few weeks ago. The @wire documentation states "If a reactive variable changes, the wire service provisions new data" but I do not observe that being the case.
How can we use the output of one wired apex call as the input to another?
get
properties are not watched and so yeah, i am surprised it ever worked for you at all...