You need to sign in to do that
Don't have an account?

Referencing child data from a master-child Select statement (Relationship query)
My client has set up a custom object named Industry_Type__c that is a child object of the Account record. The child relationship name is "IndustryTypes." To make things confusing, this custom object has a field that is also named Industry_Type__c.
I'm writing some unit test code like this:
No errors. The problem is, I can't figure out how to reference the Industry Type field value using dotted notation or any other way.
Here are the things I've tried:
String testval = acct.Industry_Type__c.Industry_Type__c;
String testval = acct.IndustryTypes.Industry_Type__c;
String testval = acct.IndustryTypes__r.Industry_Type__c;
String testval = acct.IndustryType__r.Industry_Type__c;
Industry_Type__c[] test = acct.IndustryTypes;
The first 4 attempts give me "Invalid foreign key relationship" errors, and the last one throws "Invalid Field IndustryTypes".
I've read page 28 and page 53 of the Apex Reference Manual and read the online SOQL doc but I still don't understand how I can do this. Do I need to use queryResult()?
http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content%2Fsforce_api_calls_soql.htm|SkinName=webhelp
Thanks
David
I'm writing some unit test code like this:
Code:
Id acctID = lcr.getAccountId(); Account acct = [select Id, Name, (select Industry_Type__c from IndustryTypes__r)
from account where Id = :acctID];
No errors. The problem is, I can't figure out how to reference the Industry Type field value using dotted notation or any other way.
Here are the things I've tried:
String testval = acct.Industry_Type__c.Industry_Type__c;
String testval = acct.IndustryTypes.Industry_Type__c;
String testval = acct.IndustryTypes__r.Industry_Type__c;
String testval = acct.IndustryType__r.Industry_Type__c;
Industry_Type__c[] test = acct.IndustryTypes;
The first 4 attempts give me "Invalid foreign key relationship" errors, and the last one throws "Invalid Field IndustryTypes".
I've read page 28 and page 53 of the Apex Reference Manual and read the online SOQL doc but I still don't understand how I can do this. Do I need to use queryResult()?
http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content%2Fsforce_api_calls_soql.htm|SkinName=webhelp
Thanks
David
--Chris