Tags as Subquery?

  • 1
  • Problem
  • Updated 3 years ago
  • Not a Problem
I have a table of contacts.

I would like to be able to filter these contacts based on a table filter, using values of a ContactTags model, and then using the selection as the value of a condition.

This condition would limit the Contacts to only contacts with that selected tag.

I just started down this path when I hit this error in a preview: 1. An error occurred while attempting to perform the following SOQL query: SELECT Id,GCP_Interest__c,Name,Birthdate,Account.Name,AccountId,CreatedDate FROM Contact WHERE (Id in (SELECT ItemId FROM ContactTag)) LIMIT 101 Error:Entity 'ContactTag' is not supported for semi join inner selects .

Is this a hard stop on one of Salesforce's unqueryable objects, or am I approaching this the wrong way?

Thanks,

Jacob
Photo of Jacob Flatter

Jacob Flatter

  • 338 Points 250 badge 2x thumb

Posted 5 years ago

  • 1
Photo of krista06880

krista06880

  • 816 Points 500 badge 2x thumb
I have the same question . . .. any answer as yet?
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
This is indeed a hard stop because of a Salesforce limitation.   The object is queryable directly,  but not as a "semi join inner select" which means you can't use it to filter the parent contact object.  You could build a table directly accessing the contact-tag object,  and even build a tag filter on that table - but you would end up with multiple records per contact (one record per contact / tag combination) and that's not exactly what you want. 

Sorry about this. 
Photo of Joe Ort

Joe Ort

  • 2,256 Points 2k badge 2x thumb
Do Topics get around this problem?
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Joe...We were able to use Topics to filter a list of Tasks.  You need to create a child relationship from your object to Topics.  You will also need a model that brings back a list of Topics (i.e. the 'tags').  Then create a subquery join to Topics.  I've attached a screenshot of the trickiest part (the filter with subquery condition).

Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Yes,  Topics allow more query options than Tags do..