function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PauloPaulo 

Query an accounts contact

I'm trying to query an account's contact by recordtypeid and account name. How would my soql statement look? Currently I have this but nothing is returned.
 

SELECT ID,FirstName, LastName, Primary_Contact_Title__c, Email, Phone, Fax, MailingStreet, MailingCity, MailingState, MailingPostalCode FROM Contact WHERE Account.= '" + strAccount + "' AND RecordTypeId = '" + strRecordTypeId + "'"

BuenavadBuenavad
I think the correct way is writing...


Code:
SELECT ID,FirstName, LastName, Primary_Contact_Title__c, Email, Phone, Fax, MailingStreet, MailingCity, MailingState, MailingPostalCode FROM Contact WHERE Account.Name= '" + strAccount + "' AND RecordTypeId = '" + strRecordTypeId + "'"

 
if you have the Account ID you should write   ...AccountId = '"+string+"' .... but if you have the name is Account.Name = '"+string+"'.....

Regards
canonwcanonw
It is a good practice to test the SOQL in Apex Explorer.

Also, the result set should return error message.  Your code should check out error.