How do I create a link on field in an aggregate table?

  • 3
  • Question
  • Updated 3 years ago
  • Answered
I have an aggregate model displaying results in a table. Some of the "grouping" fields shown in the table are the name fields of relevant records, but they don't appear as links to those records as they normally would when including those fields in a field editor, template, or a table based on a "normal" model. How do I get these links to appear so that users can click and go to the record? In some cases I also want to create an alternative link, because I need to supply an additional parameter, but I don't seem to be able to create a template with data from fields in the aggregate model. How would I make such links?
Photo of Peter Bender

Peter Bender, Champion

  • 6,296 Points 5k badge 2x thumb

Posted 6 years ago

  • 3
Photo of Zach McElrath

Zach McElrath, Employee

  • 52,276 Points 50k badge 2x thumb
Official Response
This is doable --- but it takes some trickery. There are a couple of different approaches which could be taken to make this work, so to understand why Skuid doesn't do any of these by default, it's important to know what the holdup is.

The main issue is that, with Aggregate queries, Salesforce doesn't let you just add arbitrary fields to the query --- if a field is in your query, it MUST be either Grouped, or Aggregated (with a function such as COUNT, SUM, etc.). This becomes a problem when you're trying to Group by Lookup fields, because you have to pick either the related record's Id or Name field to Group by. Naturally, you'd think, pick the Name field --- that way you see something that's actually human-readable. But, if you don't retrieve the Id, then you can't generate a Hyperlink to that related record's Detail page!

How to get around this?

Two strategies come to mind immediately. I'll show how to do the first of these:

(1) - easiest. Group first by Id, then by the Name field. That way you have both pieces of data in your Model, and your groupings will be identical.

(2) - more complex. Just group by Id, and then do a separate query on all records that match those Ids, for instance, get all Accounts in a separate Model, querying for the Accounts' Names, and then match up the Ids with Names and display appropriately.

So, going step by step through Strategy 1, we'll do an example where we do Aggregate Opportunity statistics, and group by Account Id and then Account Name.

1. Group first by the Opportunity's associated Account's Id, then by the Account Name.
-NOTE: it's very important the ORDER in which you do this IF you can have duplicate Account Names. FIRST Group by the AccountId, then by AccountName.

2. Drag a TEMPLATE Component into your Table.

3. Use HTML to create a Hyperlink in the Template, using the Account Id for the URL and the Account Name for display

-This works because your Aggregate Query is producing Rows which have both an "accountId" "field", containing the primary grouping field's value, and an "accountName" field, containing the secondary grouping field's value.

IMPORTANT: Use TRIPLE Mustaches around the fields.

-BONUS: You can have the link open up a separate window by including the "target" attribute in your link.

That's all it takes!