function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Clay LovelessClay Loveless 

Solutions, Categories and SOQL: how to get Solutions in a Category?

I'm new to Apex, SOQL and the entire Salesforce world, so please forgive me if this is a silly question.

I'm working with a partner who has grouped their Soultion objects into categories. I can see these groupings with no problem in the UI of the Salesforce dashboard (Solutions tab), but cannot for the life of me conjure up the correct SOQL query to get a list of Solutions for a particular category.

For example, here's a query that seems reasonable based on what I've read in the documentation. Result *should* be an array of SolutionNames and SolutionNotes for Solutions in the category 'Foo'.

Code:
SELECT
   SolutionName, SolutionNote,
   (SELECT
       CategoryNode.MasterLabel
   FROM CategoryNode
   WHERE
      MasterLabel = 'Foo')
FROM Solution

 

Instead, I am treated to this error: INVALID_TYPE: Didn't understand relationship 'CategoryNode' in FROM part of query call. If you are attempting to use a custom relationship ...

For something as straightforward as "give me a list of Solutions within Category 'Foo'", I feel like I'm having a harder time than I should be.

What obvious thing am I missing? :)

Thank you!
Ron HessRon Hess
solutions are not related directly to category nodes

see this diagramInsert a Hyperlink

you will need to construct a query that combines tables using category data objects which have category id and solution id.

normaly i use eclipse and the schema viewer to construct SOQL statements , do you have eclipse installed?
Michael.WatkinsMichael.Watkins
can this be done in a single query or must you query CategoryData and then loop thru each row and issue another call?

the self service portal allows you to search solutions by category (and uncategorized) and this functionality has proven impossible so far for me to emulate in vb.net.  i keep getting the same errors as above even though apex explorer shows a seemingly valid child relationship.  :o(

please be a little more specific, as i am not understanding your suggestion. (i'm new to soql...)

we're using apex explorer so it would be grand if you could scribble a working query to pop in there to see what you are talking about.

thanks! and regards,


gbiesinger1@wavelink.comgbiesinger1@wavelink.com

This thread is a bit old but I recently struggled with something similar and thought I'd share the solution I found.

There is a relationship between CategoryNode, CategoryData, and Solution which is documented here.

However, despite the supposed relationship, a query such as the following does not work:

 

SELECT Solution.SolutionName, (SELECT CategoryData.Id FROM CategoryData WHERE CategoryNodeId = '[Category Node ID]') FROM Solution

 

Instead, the only thing that worked for me was to use the IN clause with a sub query to filter the results:

 

SELECT Solution.SolutionName FROM Solution WHERE Id IN (SELECT CategoryData.RelatedSobjectId FROM CategoryData WHERE CategoryData.CategoryNodeID = '[CategoryNodeID]')

 This seems to perform much better (and is definitely more efficient) than having to pull back CategoryData results, loop through each one, and perform another query to get Solution objects.