You need to sign in to do that
Don't have an account?
bujji
How to get Contact Ids List from Account List
Hi,
I have a account list (aList), i need contact ids list from the account list. How to do it.
Here i am getting 10 accounts, suppose if each account having 10 contacts than i want all the 100 contact ids in one list.
How to write the loop for this.Below is the code where i am getting all the 10 accounts and 100 contacts in one list.
String baseQuery = 'Select Id,Name,(select Id,Name from Contacts Limit 10) from Account ';
String finalQuery = baseQuery +' where Id IN (select AccountId from Contact) Order By Name limit 10';
List<Account> aList = Database.Query(finalQuery);
Please give me suggestions how to get contacts ids list.
Thanks,
Bujji
I have a account list (aList), i need contact ids list from the account list. How to do it.
Here i am getting 10 accounts, suppose if each account having 10 contacts than i want all the 100 contact ids in one list.
How to write the loop for this.Below is the code where i am getting all the 10 accounts and 100 contacts in one list.
String baseQuery = 'Select Id,Name,(select Id,Name from Contacts Limit 10) from Account ';
String finalQuery = baseQuery +' where Id IN (select AccountId from Contact) Order By Name limit 10';
List<Account> aList = Database.Query(finalQuery);
Please give me suggestions how to get contacts ids list.
Thanks,
Bujji
Something like this works:
So you see I just did "Contact.AccountId IN :alist" and this loads all the contacts in the list from above (which in my case is every account)
After you have constructed your alist (which you have in your question) just use the query I did (with your own field/selectors).
All Answers
Yo can do like this:
conList contains all the contacts.
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
Something like this works:
So you see I just did "Contact.AccountId IN :alist" and this loads all the contacts in the list from above (which in my case is every account)
After you have constructed your alist (which you have in your question) just use the query I did (with your own field/selectors).
I have one more scenario like, i have a list which is of type ID, it contains contact ids but i want to assign these to some campaign how to do it.
Give me some suggestion.
Thanks,
Bujji
or to that effect (I'm speed pseudo-coding here!). That will insert new campaignMember records for those contacts.
You can read more on the CampaignMember object here https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_campaignmember.htm
Do we need to change any thing.
Thanks,
Bujji
Thanks,
Bujji
A slight difference in the single query
Here, how do we access the Contact details from sAcc using dot notation?
will it considering account names or account ids...I tried to use below
List<Contact> clist = [SELECT Id, Name,AccountID FROM Contact WHERE Contact.AccountId IN :alist]
but am getting Account name instead of AcountID.
Could anyone please help me in this.
This is from two years ago but looking at your code the first AccountID call has an uppercase D. Hope that helps.