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
SFDCDevQASFDCDevQA 

Contains method on child to parent relationship query

I am trying to use the contains method on a string field in my relationship query for the list below but I get Compile Error: unexpected token: 'HSS'.  To get to the field it is going from UserTerritory2Association to Territory2 to Territory2Type. (Child to Parent to Parent all standard objects) If I just say WHERE Territory2.Territory2Type.DeveloperName = 'HSS' then it works fine but I don't want to have to specify every single type.  Instead I want to say if the type MasterLabel contains certain characters then it should grab those.  Why is it not letting me use the contains method?

Thanks,
Amanda

List<userterritory2association> userTerritoryAssociations = [
                                                                            Select id, UserID, territory2Id, RoleInTerritory2, Territory2.Territory2Type.Priority, Territory2.Territory2Type.MasterLabel from userterritory2association Where Territory2.Territory2Type.MasterLabel.contains( 'HSS' )
                                                                            ];
Ketankumar PatelKetankumar Patel
try using Like '%XXX%' in your query.

List<userterritory2association> userTerritoryAssociations = [Select id, UserID, territory2Id, RoleInTerritory2, Territory2.Territory2Type.Priority, Territory2.Territory2Type.MasterLabel from userterritory2association Where Territory2.Territory2Type.MasterLabel like '%HSS%'];