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
Joaquin IudicaJoaquin Iudica 

Lightning web components that shows filters (to filter records)

Hello everyone! I'm new to salesforce, and to development also, so I'm sorry if I'm not clear. I have to make a lightning web component that shows filters (created in apex). The component is not responsible for making the query, or to show the results, only the filters (another component would use this one, to get the filters with their values and then making the query). I made an apex class to test, what it does is creating some filters for the Account object, and then exporting them to be able to import from the LWC:
public static QueryFilters getFilters(){
        QueryFilters filters = new QueryFilters();

        filters.add(new QueryFilters.StringFilter(new QueryFilters.Field(Account.Name)));
        filters.add(new QueryFilters.InFilter(new QueryFilters.FieldOptions(Account.sobjectType, Account.Industry)));
        filters.add(new QueryFilters.NumberFilter(new QueryFilters.Field(Account.NumberOfEmployees, 'Empleados desde'), QueryFilters.Operator.GE));
        filters.add(new QueryFilters.NumberFilter(new QueryFilters.Field(Account.NumberOfEmployees, 'Empleados hasta'), QueryFilters.Operator.LE));
        filters.add(new QueryFilters.FilterWithOperators(new QueryFilters.NumberFilter(new QueryFilters.Field(Account.NumberofLocations__c))));
        filters.add(new QueryFilters.BooleanFilter(new QueryFilters.Field(Account.Tested__c)).selectize());
                
        return filters;
    }

    @AuraEnabled
    public static List<Map<String, Object>> getFiltersJson(){
        return QueryFilters.export((List<QueryFilters.ExportableFilter>)getFilters().filters);
    }
The method 'getFiltersJson) is auraenabled, and returns an export to be able to read it from the lwc. If you see, it is a list of map<String, Object>. How do I work with that method from the javascript file? What should I do to get its data?

This would be the html for the LWC (something of the sort):
<template>
    <lightning-card title="Filtros" icon-name="standard:account">
        <template iterator:it={filters}>
            <lightning-input
                 onchange={getValue}
                 key={it.value.label} 
                 if:true={it.value.isInput} 
                 type={it.value.type} 
                 label={it.value.label}>
            </lightning-input>
            <lightning-input
                onchange={getValue}
                key={it.value.label}
                if:true={it.value.isBoolean}
                type={it.value.type}
                label={it.value.label}>
            </lightning-input>
            <c-lwc-multi-select
                onchange={handleOnChange}
                key={it.value.label}
                if:true={it.value.isMultiSelect}
                label={it.value.label}
                options={it.value.options}>
            </c-lwc-multi-select>
        </template>
    </lightning-card>
</template>
Auler CordobaAuler Cordoba
Hi Joaquin, I'm having this problem in this moment.