You need to sign in to do that
Don't have an account?
mriz
how to query and use contact id from account object
I want to fetch id of contact person associated with an Account. And then use it in VF page.
SOQL
This line compiles well.
But i don't how to use store contact Id from "ac" to "cId".
Any help would be highly appreciated.
Query:
SOQL
Account ac=[Select id,name,(select id,phone from Contact) where name='xyz' limit 1]; public ID cId;
This line compiles well.
But i don't how to use store contact Id from "ac" to "cId".
Any help would be highly appreciated.
Query:
It's still a list, with one item.
You can retrieve Id of first related contact in that list: ac.contacts.get(0).Id
All Answers
1. The below query will give you all contacts which are associated with an account whose name is xyz.
2. The below query will give you the contacts who account name is 'XYZ'
-Thanks
Ashlekh Gera
you can have multiple contacts related to 1 account, so you have to go through all queried contact, like:
Marek
something like --> ac.contacts.id
Reason being that this query compiles successfully, that perhaps means that id is being fetched from contact.
I only need to get ID of associated Contact without having to query another object (Contact in this case).
It's still a list, with one item.
You can retrieve Id of first related contact in that list: ac.contacts.get(0).Id