I have built a custom list view that lists custom objects. The list view component allows filtering based on a field of the custom object. This all works smoothly, but I want to add a feature where the default filter view is based on the profile the user is viewing from. Currently it is default to "All".
1 Answer
Probably modify the code a bit like -
@track currentFilter;
@wire(getUserId, {})
getUserIdData({ error, data }) {
if(data) {
if (data === '00e1F000000mZ8y') { // if it is DF profile
this.currentFilter = this.DF;
} else if (data === '00e1F000000mZ9D') { // if it is RAC profile
this.currentFilter = this.RAC
} else {
this.currentFilter = this.ALL;
}
} else if (error) {
//handle error
}
}
-
I tried this, except I had my
getUserId
method return a String instead (since I don't know what data typeDF
,RAC
, andALL
would be for when specifying what kind of data type to return. I did the comparisons in your if statements in my method itself, However it looks like it still defaults toALL
:(– LiaJun 23, 2021 at 19:51 -
Please modify your question and add the Apex logic. It defaults to ALL probably because no other conditions are matching. Also if you could shed more clarity on what you are looking for that would be helpful.– pk1772Jun 24, 2021 at 10:27
-
-
I see what's wrong.
UserInfo.getProfileId()
would return 18 char ID and you are comparing with 15 char. So the checks are failing and it is going toelse
block.– pk1772Jun 24, 2021 at 12:25 -
115 digit case-sensitive version is referenced in the UI and also visible in browser 18 digit case-insensitive version which is referenced through the API– pk1772Jun 24, 2021 at 12:37
ALL
? A variable or string?const ALL = 'All';
.connectedCallback()
likethis.currentFilter = this.ALL;
or simply use it like@track currentFilter = 'All';
in the declaration.userId
variable and assign the correct filter option?