You need to sign in to do that
Don't have an account?
Manish Anand 10
Parent to Child Relationship:Issue
Hi,
I am trying to display all accounts, and for each account, the first and the last name of each contact associated with that account.
I am trying below APEX code.
List <Account> Res = [Select Account.Name, (Select Contact.FirstName,Contact.LastName from Account.contacts) from Account];
For(Account a:Res) {
//System.debug('Account Name:' +a.name);
//System.debug('Contact FirstName:' +contact.firstname);
//System.debug('Contact Last Name:' +contact.LastName);
}
It displays the account name perfectly fine. But for Contact FirstName, it displays: FirstName , similarly for lastname it displays:LastName.
What, I am missing, here?
I am trying to display all accounts, and for each account, the first and the last name of each contact associated with that account.
I am trying below APEX code.
List <Account> Res = [Select Account.Name, (Select Contact.FirstName,Contact.LastName from Account.contacts) from Account];
For(Account a:Res) {
//System.debug('Account Name:' +a.name);
//System.debug('Contact FirstName:' +contact.firstname);
//System.debug('Contact Last Name:' +contact.LastName);
}
It displays the account name perfectly fine. But for Contact FirstName, it displays: FirstName , similarly for lastname it displays:LastName.
What, I am missing, here?
Use this code:
Regards,
Mahesh
All Answers
I tried with the SOQL statement pasted above by you. It throws an error-unexpected token: Contacts
Use this code:
Regards,
Mahesh
However, the result is same as mentioned in my detail description.
Any help?
Regards,
Manish.
Did you enable the Person Accounts?
http://resources.docs.salesforce.com/200/8/en-us/sfdc/pdf/salesforce_B2C_implementation_guide.pdf
Regards,
Mahesh
Thanks Again, Mahesh.
Regards,
Manish.