You need to sign in to do that
Don't have an account?
ethanone
LWC/Apex returning user list with parameters
I'm trying to display the list of acitve users in the same branch office as the logged in user in a LWC.
I have an apex class that looks like this:
I have an apex class that looks like this:
@AuraEnabled(cacheable=true) public static List<User> getMktUsers(String usrId) { User ThisUser = [SELECT Id, Name, Office__c FROM User WHERE Id = :usrId LIMIT 1]; return [SELECT Id, Name FROM User WHERE Office__c = :ThisUser.Office__c and IsActive = True]; }I have refer to it in my LWC js file like this:
import { LightningElement, api, track, wire } from "lwc"; import getMktUsers from "@salesforce/apex/Top100.getMktUsers"; import Id from "@salesforce/user/Id"; export default class Top100 extends LightningElement { @wire(getMktUsers, { usrId: { Id } }) wiredUsers; }I call it in my html file like this:
<ul class="slds-list_ordered"> <template for:each={wiredUsers.data} for:item="wuser"> <li key={wuser.Id}> {wuser.Name} </li> </template> </ul>I'm able to get lists of users to appear if I hard code the office name, but when I try to pass in the Id to determie the current user's office, i get nothing appearing. I do not know how to debug this. Can anyone help?
1. check if you are getting the id in the apex code
2. check if the query is returning values to client-side
If it is working with hardcoded value, then it will be an issue at Apex side
- Naveen K N
For #2, I can't seem to get the return value out in a console.log statement - i mean, i can't find it in the logs, but no deployment or runtime errors. using alert jsut gives me [object object], so how do I view the user list value in the browser?
public static List<User> getMktUsers(String usrId) {
System.debug('Id is ' + usrId);
}
check the value of this one in the developer console > logs section. In case if you are getting id everything is fine from the js code.
#2
again the same, check the value of this query return [SELECT Id, Name FROM User WHERE Office__c = :ThisUser.Office__c and IsActive =True];
in the system.debug and see if you are returning any records.
In case both of them are fine in these two, you need to troubleshoot at the client side.
- Naveen K N
- Naveen K N