I have a junction Object called Service_Transaction_Type__c that creates a many-to-many relationship between two other custom objects (Service_Offering__c and Transaction_Type__c). I am also working with another custom object that has a rather long name (referred to as CustomObject__c here). CustomObject__c is a junction Object between Service_Offering__c and Account.
Typically, the only users who would be logged in as ":UserInfo" are customer portal users, so they will always have an associated contact.
Below is how I have started this query:
User u = [SELECT Id, ContactId, FirstName FROM User WHERE Id = :UserInfo.getUserId()];
Contact c = [SELECT Id, LastName, AccountId FROM Contact WHERE Id =:u.ContactId];
Account a = [SELECT Id, Name FROM Account WHERE Id = :c.AccountId];
List<CustomObject__c> sn = [SELECT Id, Name, Service_Offering__r.Name FROM CustomObject__c WHERE Account__c = :a.Id];
What I need to do next is come up with a list of all of the Transaction_Type__c names for all of the Service_Offering__c's that were returned when I queried the List(CustomObject__c> sn.
I have tried a number of ways of going about doing this. Some involving for loops or trying to create a list of Service_Offering__c's to query next. Below is an example of how I have attempted this:
List<Service_Offering__c> serviceList = new List<Service_Offering__c>();
for (CustomObject__c snanaRecord : sn){
serviceList.add(snanaRecord.Service_Offering__r);
}
List<Transaction_Type__c> trxNameList = [SELECT Name FROM Transaction_Type__c WHERE Service_Transaction_Type__r.Service_Offering__c IN :serviceList];
The error that keeps getting thrown is: "Didn't understand relationship 'Service_Transaction_Type__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name." I am using the "__r" in the field path. I would appreciate any input as to where I may be going wrong here.
Thanks,
CP