When working with data repeaters, data tables, and data functions, you can filter the data you retrieve in many ways. In this topic, we explore two options— fixed values and URL query strings—to illustrate some common filtering techniques.
Required Editions
| Available in: Salesforce Classic |
|
Available for purchase in: Enterprise, Performance, and Unlimited Editions Available (with limitations) in: Developer Edition |
Example 1: Use a Fixed Value to Filter Results
In our first example, we have a custom object called “News” that stores company news and events. Each news item has a Status picklist that can be set to either In Progress or Approved. We only want to display approved news items on our Company News page. In this case, we can use a fixed value to filter the data in the News object.
In this scenario:
- Add a data repeater to the page and configure it as follows:
- Select the News custom object.
- In the Filters section, set the criteria to Status Equals Fixed value.
- Enter Approved in the Value text box.
Approved. - To display the required fields, such as Title, Description, and Date, on the page, add data elements to the data repeater.
Example 2: Use a URL Query String to Dynamically Filter and Display Results on Another Page
In our second example, we have a custom object called “Products” that stores product information. However, some products are only available in certain locations, so we like to let customers view the products in their nearest city. In this case, we could create a Locations site page that contains links to each available city.
We want each link to open the Products site page, but only display products based on the user's selection. We can do this using URL query strings, which let us pass variable content between HTML pages. The variable information in this case is the product location; the data repeater doesn’t know which products to return until the user makes a selection.
In this scenario:
- Add a data repeater to the Products page and configure it:
- Select the Products custom object.
- In the Filters section, set the criteria to City Equals URL query string.
- In the Value text box, enter the variable name—in this case, location.
- If query string is missing dropdown list, select Don't apply this filter item. This option is used when a customer wants to view all products without filtering.
- Click Save.
- Add data elements for the fields you want to display, such as Product Name, Description, and Price.
- On the Locations page, add a data repeater and select the Products custom object.
- Add a data element to the data repeater to represent the
City field and configure it:
- Select the City field as the field to display, because we want to use the name of the city as the hyperlink.
- Select Text as the display format.
- Select Add a hyperlink to display a URL on the page.
- In the Link to dropdown list, select An item in your site.
- Select Page as the type and select the Products page. (If you can't see the list of pages, place your cursor in the URL text box and press the DOWN key on your keyboard.)
- Change the URL value to
/product?location={!City}. In this case,
{!City} is a placeholder for the value of a
record's City field. When the page first loads,
{!City} is replaced with the correct value,
such as Dallas, which creates this URL for that record:
/product?location=DallasWhen clicked, the Products page opens with
Dallaslisted as the value of the location variable. - For the tooltip, select the City field and click Customize.
- Change the value to Show me products available in
{!City}.
Again, the value of the City field replaces the {!City} placeholder for each record when the page loads.
Now, when the Locations page loads, the data repeater displays the location of each
product as a link. When a customer clicks a link, such as Dallas, the Locations page
passes location=Dallas to the Products page. As
the Products page loads, the data repeater uses this value to dynamically return
only records where the City field contains the value Dallas.