0

I have a checkbox: Archive on a Custom object which gets checked on the records which were two hours old. I wanted to pull these records in a separate tab: Archived Records in a community page. I can see a standard component Record List which pulls all the records irrespective of any filters. How can I create/customize a filter to display only Archive checkbox checked-in records?

1 Answer 1

1

In order to apply your custom filter, you will most likely have to create a custom lightning component with a server side controller to fetch your custom object records.

The Lightning Component Developer Guide : Working with Salesforce Records

has this well documented so I wont post a detailed explanation.

Example server side controller:

public with sharing class potatocontroller { 

    @AuraEnabled
    public static List<potato__c> getPotatos() {
        List<potato__c> potatos = new List<potato__c>();
        potatos = [Select ID, Name from potato__c WHERE checker__c=true];
        return potatos;
    }
}

above, I am filtering on records that are 'checked'.

then, you will have to use a client side controller to invoke your @AuraEnabled apex class:

({
    getpotatos: function(cmp){
        var action = cmp.get("c.getPotatos");
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                cmp.set("v.potatos", response.getReturnValue());
            }
        });
     $A.enqueueAction(action);
    },

})

and render your records in your component:

<aura:component controller="potatocontroller" implements="forceCommunity:availableForAllPageTypes" access="global" >
    <aura:attribute name="potatos" type="c.potato__c[]"/>

    <ui:button label="Get potatos" press="{!c.getpotatos}"/>

    <aura:iteration var="potato" items="{!v.potatos}">
        <p>{!potato.Name} : {!potato.Id}</p>
    </aura:iteration>

</aura:component>

when working with custom objects, you must add the namespace prior to the object type.

Additionally, you might want to modify the styling in your design file.

4
  • But there should be some way or other to get to the filter criteria in the standard Record List component right?
    – SatyaV
    Commented Aug 20, 2017 at 17:40
  • like a permanent filter? because i know that OOTB, you can change it (users as well)
    – glls
    Commented Aug 20, 2017 at 17:43
  • if you want the component to ONLY show based on that filter, you will have to go custom, as far as I am concerned
    – glls
    Commented Aug 20, 2017 at 17:56
  • Just realized: We can create a new List View on the custom object of the standard Salesforce Classic with the necessary filter criteria, which shows up in the Record List community component.
    – SatyaV
    Commented Aug 20, 2017 at 20:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .