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

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?

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!

Got it working - thanks!

This is so cool!

I’m trying to create a link from an aggregate summary table and I’m not able to create the link using the above method… Any advice? “/{{{member.Id}}}” target=“_blank”> {{{Member.Name}}} (begins with-- <a href= ends with )

instead of “member.Id” and Member.Name, you’ll have to use the Alias Names corresponding to those, e.g. “memberId” and “memberName”, so your Template would be:

<a href="/{{{memberId}}}" target="_blank">{{{memberName}}}</a> 

You da man! Thanks for the help

Sorting??? Is it Possible to sort on a SUM field within my aggregate table? I would like to sort by my Sales Summary field…sort from High to Low thanks

You can do default sorts, but not dynamic sorts. To add a default sort, go to your Aggregate Model’s properties, and in the “Order Records by” property, put your Order by SOQL, e.g. SUM(Sales_Summary__c) DESC In order to sort on a field/aggregation in Aggregate models, you MUST either be grouping by or aggregating by that field/aggregation.

Hey Zach,

I’m trying to do the same and I’m getting an error:

Field must be grouped or aggregated: Name
An unexpected error has occurred. Your solution provider has been notified. (skuid)

This is what my template field has: <a href=“/{{{InvoiceId}}}“target=”_blank”>{{{Name}}}

Did you add Name as a Grouping field?

I did. However, the way I’m getting the Name field is not by going to the parent record and choosing Name (the Name field doesn’t show up in the list of available fields in the parent record when I click on the little arrow), rather I select the parent record from the list of fields on the child object. This automatically adds two fields to my grouping fields.
1. Parent__c
2. Parent__r.Name

I hope that was clear, sorry I don’t have the tech-lingo down yet