How Can I Sort Contacts by Campaign as in SF Contact Views?

  • 1
  • Question
  • Updated 5 years ago
  • Answered
How Can I Sort Contacts by Campaign as in SF Contact Views? Where it gets tricky is the Campaign Member object is the connector between Contacts and Campaigns, so I can't quite figure out how to set up a filter on a Squid Contact Tab.

Any pointers?
Photo of krista06880

krista06880

  • 816 Points 500 badge 2x thumb
  • a tad frustrated I can figure it out

Posted 5 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Hi Krista,

This is somewhat tricky, but it is doable! If you just want to skip right to a working example, go to the bottom and copy/paste the XML into a new Skuid Page's XML
(See this tutorial for how to copy/paste/share Skuid Page XML)

Here's the end product, a page where you can filter your contacts to just those that are a member of any Campaign, and then optionally select a particular Campaign that they must be a member of:





Here's how this is done:

1. Create a Model on the Campaigns that you want to Filter on


2. Create a Sub-query Condition on your Contacts model to allow you to filter to show just Contacts that have CampaignMember records for a particular Campaign:


Here you will have to create 2 Conditions, both with State = "Filterable (Default Off)", and both with unique names. The parent condition should be called "MemberOfACampaign", and be of type "Result of a Subquery", with Join Object = "CampaignMember" and Join Field = "ContactId".

Once you've created this Condition, add a Sub-Condition on the CampaignId field, again Filterable (Default Off), with Name "CampaignId".

3. Create 2 Filters on your Contacts Table
Filter 1:


Label: "Require Contacts to be a member of a Campaign".
Type: Toggle
Effects: Activate the MemberOfACampaign condition.

Filter 2:





Filter Off Option Label: "Select a Campaign...".
Type: Select Option
Condition: CampaignId

Add a single Source, of type "Model", on the Campaigns model, and you can ignore Label Template and Value Template.

**If you want, for this page, to ONLY ever show Contacts that are a member of a Campaign, then you can change the "MemberOfACampaign" condition to be "Always On", and can remove Filter 1 (called "Require Contacts to be a member of a Campaign".

working example Skuid Page:

<code>

<skuidpage showsidebar="true" showheader="true" tabtooverride="Contact">
<models>
<model id="Contact" limit="100" query="true" createrowifnonefound="false" sobject="Contact">
<fields>
<field id="FirstName"/>
<field id="LastName"/>
<field id="CreatedDate"/>
</fields>
<conditions>
<condition type="join" value="" field="Id" operator="in" enclosevalueinquotes="true" joinobject="CampaignMember" joinfield="ContactId" state="filterableoff" inactive="true" name="MemberOfACampaign">
<conditions>
<condition type="fieldvalue" value="" enclosevalueinquotes="true" field="CampaignId" state="filterableoff" inactive="true" name="CampaignId"/>
</conditions>
</condition>
</conditions>
</model>
<model id="Campaigns" limit="100" query="true" createrowifnonefound="false" sobject="Campaign" orderby="Name">
<fields>
<field id="Name"/>
<field id="Id"/>
</fields>
<conditions/>
</model>
</models>
<components>
<pagetitle model="Contact">
<maintitle>
<template>{{Model.LabelPlural}}</template>
</maintitle>
<subtitle>
<template>Home</template>
</subtitle>
<actions/>
</pagetitle>
<skootable showconditions="true" showsavecancel="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Contact" mode="read">
<fields>
<field id="FirstName" allowordering="true"/>
<field id="LastName" allowordering="true"/>
<field id="CreatedDate" allowordering="true"/>
</fields>
<rowactions>
<action type="edit"/>
<action type="delete"/>
</rowactions>
<massactions usefirstitemasdefault="true">
<action type="massupdate"/>
<action type="massdelete"/>
</massactions>
<views>
<view type="standard"/>
</views>
<filters>
<filter type="toggle" affectcookies="true" label="Require Contacts to be a Member of a Campaign">
<effects>
<effect action="activate" value="" condition="MemberOfACampaign"/>
</effects>
</filter>
<filter type="select" filteroffoptionlabel="Select Campaign..." createfilteroffoption="true" affectcookies="true" condition="CampaignId">
<sources>
<source type="model" model="Campaigns">
<labeltemplate>{{Name}}</labeltemplate>
<valuetemplate>{{Id}}</valuetemplate>
</source>
</sources>
</filter>
</filters>
</skootable>
</components>
<resources>
<labels/>
<css/>
<javascript/>
</resources>
</skuidpage>

Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Zach this is great! Thanks. I'm guessing that Krista is probably going to want to add another condition to the Campaign model that limits campaigns that are active using the "is active" or "status" fields. Otherwise over time the drop down list is going to get LOOOOONG...
Photo of krista06880

krista06880

  • 816 Points 500 badge 2x thumb
Rob,

You read my mind. Only . . .where do I add that model/filter since we would need to filter on the Campaign Status field and the filter Zach built is on the Campaign Member. The Campaign Status field is on the Campaign object. I don't know how to get from here to there from a condition- filter perspective.

Also, a random question from left field: can one filter on Tags in Squid or pull up tagged Contact records in a Skuid page

Thanks!
Photo of krista06880

krista06880

  • 816 Points 500 badge 2x thumb
The above produced an error with the toggle filter option. Apex heap size too large: 6199207. We have an usually large database (359,982 contacts).

To avoid the issue , I turned off the toggle following your instructions to show only those Contacts that are campaign members. I changed the "MemberOfACampaign" condition to be "Always On", and removed Filter 1 (called "Require Contacts to be a member of a Campaign".

So, good news, the page loads without the Apex heap too large error. However, when I attempt to select a Campaign, nothing appears when I type in the name of the Campaign in whole or in part.


Thoughts?