Video tutorials
/
How to Dynamically Filter Metrics by Days on Record Pages in Salesforce
Lightning Pages

How to Dynamically Filter Metrics by Days on Record Pages in Salesforce

A Coming Up Next card on the account page: pick 7 or 30 days, metrics for opportunities and tasks update.

Intermediate
12:33
Tutorial
How to Dynamically Filter Metrics by Days on Record Pages in Salesforce
Play video
Chapters
Click a chapter to jump to it
Watch on YouTube

What you will build

Build a Coming Up Next component on the account page, with metrics that follow a time frame chosen in a combobox. For Salesforce admins who build Dynamic Components for record pages.

  • A combobox that drives a reactive query on a time frame, such as 7 or 30 days
  • Formulas and resources that turn the text choice into a number
  • Metrics for upcoming opportunities and tasks
  • A layout with cards, columns and custom styles
  • $Component.recordId to limit the metrics to the current record

Transcript

0:00 Transcript

Hello and welcome to this new video tutorial about the Avonni dynamic component. And today I'm going to dig into one example I build on this account record page is this one. So I build a dynamic component to display what's coming up next for that specific record information. And what I did which I find very interesting in it's I put a combo box and when I select any item from the combo box it will dynamically refresh the query from the matrix based on you know the number of days. So today I'm going to show you how to build you know this kind of component and also showing you the logic behind this especially with the reactive query based on you know text value coming from a combo box and that's what I'm going to show you today. Let's dive in. So first we are going to open the Avonni component application from the app launcher and let's create our new component. Name it account. Coming up. Next. Here it's really important to define the target page object because this component would will because this component will live on an account page. So the dynamic components needs to be aware of the context where it operates because we will use the dollar sign component attribute to fill out some information in our dynamic component. So let's just select the account page object. So now we can start building our component. First I will start by dragging the card component. And from there what's coming up next. We can add an icon if we want. Let's take the feed one. And we can fine-tune the style of the card. So I would just play a little bit with the uh font size uh the weight of the text. You can play with color, border, bottom size, basic stuff. Okay. Next, we can drag the combo box element. So here I can drag the combo box directly inside the card on the top right action. And now I can configure the combo box. So manual value that will be next 7 days. So the combo box value let's set to manual. Let's define a label next 7 days. And here that's really important because instead of you know having the next seven days automatically prefilled as a value I will remove this and just typing seven. Why? because this is the value we will use on the reactive query and that's why that's what I will show you in in few minutes. Then we can do the same for next 30 days. Let's replace the value with 30. Now for the label value let's say so that's the default value when the component is showing up for the first time we can set to seven. So that will be the the default selected value and then we can play with the variant like label iden. Okay. At any time feel free to click on the preview button to see how this looks like. Next, now we can drag the column component because we want to create a two colon layout and inside each column I will drag the matrix component one metric on one column to display you know what's coming up next based on the metric. So here let's take this add a new column. We can set fixed size value for the column. The same for the other one to be consistent. We can also apply some horizontal spacing between items. So now I have some breathering room. So now I have some bre. So now I have some space between column. Okay. Now let's drag the metric component and let's configure the metric. So here the first one would be deals and the value that's something here I want to do a query for the value on the opportunity object and then to count the number of opportunities. So let's select the opportunity ID aggregate function count and here yes I will need to add a filter because I need to filter the matrix information but before doing that I will need to create a resources and I will show you why next. So before putting the filter because basically what I like to do for the filters I like to filter information where the account ID first is equal the map value coming from the dollar sign component and then record ID because we set the target page object initially. Now the dynamic component is aware of the context where it operates and it can note you know the record ID. Now I also need to add another condition based you know on the close date which is equal to value and here I will select date literal and the value will be next next days and here this is basically I want to map the number of days to the value coming from the combo box but I can't do that right now and I will show you Why? Because right now if I'm going back on the combo box, that's what we did. We set the value to seven. But this is a text value. This is not a number. So we need to create a formula resource to convert the text value to a number. Let me show you how. And then we will be able to use this on our filter. So I'm going on the resource tab. New resource formula. Let's say converted text data type it's number that's a number I want to have a number and now I will enter the formula which is value or we can select the function so value and text we removing we are removing this and select you know from the combo box value text. So this will convert the value from the combo box using the formula as a number. Okay. And now if I'm going back on the metric, I can add my other filter. So I can say yes. I want also to fit on the information where the close date is equal the value date literal next x days and here number of days. I will select mapped and select the converted text formula I just created as a resource. That's it. That's all I need to do. So now this metric would be reactive based on the selection made on the combo box which is very interesting. So now we can take the metric again and let's apply some you know styling around the matrix. So I will create a custom style selector. Let's say metric one. And here I can play with you know the padding. Let's add some padding around the metric element right there. Border. Let's take a border color like this one. Size one. Okay. And we can even use a background color. Okay. So, let's switch to preview mode. This is the look and feel for the metric. We can even fine-tune the metric a little bit. avatar. It's deal. So I can take and select the opportunity icon. Okay. And play with the position. If you want to make it top, bottom, left, right, that's possible. So now what you can do next if you like to put another metric you can simply copy this metric paste it and then just move it on the other column and all you need to do because it will already inherit the same you know styling settings and properties settings. You just need to edit the metric and instead of you know quering the opportunity object maybe you want to just querying the task object and count the number of task. So that would be uh the task you can select subject count filter by the where the task it's account ID is equal the map value coming from the dollar sign component and record ID for the current record id add condition and now let's select uh let's take due date same logic here date literal you know number of next number of days and here select the map value coming from the formula. And we can just maybe replace the icon to make it more accurate. and changing the label. Let's say task. So now let's switch to preview. This is what you have. You can switch to the next 30. Yes, I'm not displaying any records because I'm not live on a record page. But you can see already in preview the metric is trying to calculate the metrics based on the current record ID. So if you'd want to put that into a live page, it will automatically calculate and making sure the re the metrics are reactive based on the selection made on the combo box. Don't forget to activate the component to make sure you can use this inside App Builder. So as a quick recap what we did here, we created this component to display what come what's coming up next based on a specific record. So don't forget to set the target page object to really specifying specifying on which object this component will uh be live. And then we put the card, we put the combo box. That's really important on the combo box when you creating your option next seven days to replace this with just a number. That's value. It's a text. It's not a real number. So then if you're replacing this with a number as a text you will need to create a new formula resources to convert the text as a number by using the value formula and from that when you're using and configuring the metric that's very easy to filter the information using the map value from the coming using the map value from the converted text formula to fine-tune the matrix you'd like to display here and making sure it's reactive based on the combo box selection. Let me know if you have any question regarding this. And again, if you like to make this working on your sales source, don't forget to install the Avonni dynamic component application. And we are live on the app exchange or if you're typing a you will see this lighting page for the dynamic component. So that's the package you need to install and to make sure it's working on your set first to recreate this example. If you have any question, feel free to drop your question in the comment section below. Thank you so much for watching this.

Show the full transcript

Questions this video answers

How do I filter a metric by a number of days chosen in a combo box?

Give the combo box options plain number values (7, 30), create a Number formula resource with VALUE on the combo box value, and map it as the number of days of a Date Literal Next N Days filter.

Why can't I map a combo box value straight into the Next N Days filter?

The combo box value is text, not a number. Convert it first with a formula resource of data type Number using the VALUE function.

How does a dynamic component know which account record it is on?

Set the Target Page Object to Account, then filter with Account ID equals the mapped $Component RecordId.

See it as a use case
No items found.
Build it in your org

Free in sandboxes, 10 free production licenses.

Start free
Keep going

Related tutorials

Find your next tutorial

Browse the whole library, filtered by where it runs and what you want to build.

All video tutorials