+ Start a Discussion
baller4life7baller4life7 

TAGS in SOQL queries

Hey guys,

I have two custom objects: A and B. I want to relate these two objects via tags. So for example I show object A on my Visualforce page. Now every object B that has the same tags as object A should show up under object A:

 

VF Page:

 

A (tags: x,y,z)

 

-B (tags: x,y)

-B (tags: y)

-B (tags: x,z)

 

How can I realize that? How would the SOQL query look like?

 

Thank you very much for your effort,

Josh :-)

thomasstachlthomasstachl

Hey baller4life7,

 

I'm asuming that you use multiselect picklists for your tags, so your SOQL query would be something like:

 

SELECT Fields FROM B__c WHERE Tags__c includes ('x', 'y', 'z')

 

if you want to have only Bs with for example both x and y tags it would look like that:

 

SELECT Fields FROM B__c WHERE Tags__c = 'x;y'

 

if you want to have only Bs that include z tags and both x and y tags you would write it like that:

 

SELECT Fields FROM B__c WHERE Tags__c includes ('x;y', 'z')

 

I hope that helps for more information on filtering by multiselect picklists, here you'll find the documentation:

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_querying_multiselect_picklists.htm

 

Thomas

 

baller4life7qballer4life7q

I don't use multi-select-lists, but the native Tags-functionality of Salesforce. The query for Account tags would look like this:

"SELECT CreatedDate, IsDeleted, ItemId, Name, SystemModstamp, TagDefinitionId, Id, Type FROM AccountTag"

 

So I don't think that the multi-select-list solution is the right solution in my case. Thank you for your effort though!

 

Josh :-)