+ Start a Discussion
Rodolfo CalvoRodolfo Calvo 

Show all contacts from one simple account <query>

Hello team, 
I have this code
String soql = 'SELECT id, firstName, lastName, accountId FROM Contact';
I need to call all contacts from one simple account. 
I tried this: 
 
SELECT firstName, lastName, accountId FROM Contact WHERE accountid = '00000000000000'

This query worked fine, but my issue is calling all contact list from calling the account name: 
For example: I have Account_1, what I only have is the name, we imagine we do not have the ID, how could make this query by calling the name of the account?
I also tried this but there was no succeed.
String soql = 'SELECT id, firstName, lastName, accountId FROM Contact WHERE account.id;
How could I make this query correct? 
Thanks in advance
 
Best Answer chosen by Rodolfo Calvo
Arun GoelArun Goel
If you directly run the query in Developer c
SELECT id, firstName, lastName, accountId FROM Contact WHERE Account.name =  'Master Account'

onsole try this

All Answers

Rodolfo CalvoRodolfo Calvo
I am sorry Roh, it didn't work... 
It showed me the following error 
Initial term of field expression must be a concrete SObject: String

 
Arun GoelArun Goel
Hi Rodolfo,

Try below query
String soql = 'SELECT id, firstName, lastName, accountId FROM Contact WHERE Account.name=  \' [YOUR ACCOUNT NAME]\' ';

EXAMPLE:

String soql = 'SELECT id, firstName, lastName, accountId FROM Contact WHERE Account.name=  \'Test Account\' ';
RohRoh
Hello Rodolfo,
Here is another example, try to modify the data in this and use it.

String query = 'Select Name,id,FirstName from Object__c where Name__c =\''+Object.Field__c+'\' limit 1';
 Object = Database.query(query);


PLEASE LIKE THIS ANSWER , IF YOU LIKE IT.

Thanks,
Rohit Alladi
 
Rodolfo CalvoRodolfo Calvo
It showed me this error: 
Unknown error parsing query

At using 
String soql = 'SELECT id, firstName, lastName, accountId FROM Contact WHERE Account.name=  \' [Master Account]\' ';

 
Arun GoelArun Goel
Hi Rodlfo,

Could you please let me know how you are passing the Account.
Please provide the full code here. so that it will be easy to help you.
Arun GoelArun Goel
If you directly run the query in Developer c
SELECT id, firstName, lastName, accountId FROM Contact WHERE Account.name =  'Master Account'

onsole try this
This was selected as the best answer
Rodolfo CalvoRodolfo Calvo
Arun. 
Thanks a lot for your answer helped me a lot. 
String soql = 'SELECT id, firstName, lastName, accountId FROM Contact WHERE Account.name = \''+sAccountId_3+'\'';

This was exaclty what I needed!! :D 
Regards! 
 
Arun GoelArun Goel
Hi Rodolfo,

Nice to hear you, issue solved.

Happy to help :)

Thanks,
Arun
devin cafedevin cafe
https://holiday-hour.com/home-depot-holiday-hours/

 I will be telling you everything you need to know about the Home Depot hours, you May also check the Home depot near me Locations and Home Depot Customer Service Number.
t d 36t d 36
Cotomovies (https://techlogitic.net/cotomovies-app/) it is one of the best app i have ever used to solve this
t d 36t d 36
cyberflix (https://cyberflixtvapp.org/) what a lovely post
geeky flowgeeky flow
Download torrents from 1337x proxy unblocked (https://geekyflow.com/1337x-proxy/)
geeky flowgeeky flow
Robert AtkinsonRobert Atkinson
Download Pure IOS WhatsApp (https://www.technolaty.com/download-ios-whatsapp-for-android/) for Android smartphones for free. Visit https://www.technolaty.com/ for more modded Android applications.