+ Start a Discussion
Jordan@BracketLabsJordan@BracketLabs 

Record-tagging relationship subquery for tags

I'm trying to run a subquery on my query for a custom object to get it's public and and private tags.

 

I can't find any documentation about using this relatinoship, but I've activated tagging, and I can query for 'SObjectName__Tag' just fine - I would just prefer not to have to match them up afterward to speed things up on my object creation:

 

So I'm trying to figure out - I know this is syntactically not correct but hoping it will inspire someone to help me fix my mistakes!

 

List<SObject> customObjectListWithTags = [SELECT Id,Name, (SELECT Id,Name FROM CustomObject__Task) FROM CustomObject__c];

 Thanks...

Best Answer chosen by Admin (Salesforce Developers) 
Jordan@BracketLabsJordan@BracketLabs

The actual solution was not to use '__Tags' or '__Tag' in a subquery, I actually was able to use the following subquery:

List<SObject> SObjectList = [SELECT Id,Name, (SELECT ItemId,Id,Name FROM Tags) FROM SObject__C];

 

 

All Answers

Pan_AKPan_AK

Hi Jordan

 

You can take help of salesforce_apex_language_reference page number 61 .

I am giving you one of the Examples

 

for (Account a : [SELECT id, name, (SELECT lastname FROM contacts limit 1)
FROM account WHERE name = 'testAgg']) {
Contact c = a.contacts;
}

 

The syntax where you are lacking is CustomObject__Task .Don't use this instead use the pural name of the child field .

 

Please tick the Answer if it solve Your Issue .

Jordan@BracketLabsJordan@BracketLabs

The actual solution was not to use '__Tags' or '__Tag' in a subquery, I actually was able to use the following subquery:

List<SObject> SObjectList = [SELECT Id,Name, (SELECT ItemId,Id,Name FROM Tags) FROM SObject__C];

 

 

This was selected as the best answer