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
NicoUruguayNicoUruguay 

SOQL dynamic query throw parent's fields.

Hi.

 

I'm using dynamic soql as in this example:

 

 

String query = 'SELECT Name, Id, Account.Name FROM Contact WHERE Id=\'003A000000A0pAN\'';
Contact ct = database.query(query);

 After the excecution of the database.query, I can't use Account.Name field value. 

 

Even more, I can use Parent's fields as part of query conditions:

 

 

String query1 = 'SELECT Name, Id, Account.Name FROM Contact WHERE Account.Name =\'Acc1\' ';
List<Contact> cts = database.query(query1);

 

 

Is there any way to obtain parent's field values?

 

Thanks, 

nico.

 

 

Jeremy.NottinghJeremy.Nottingh

I used almost your exact code successfully:

 

String query = 'SELECT Name, Id, Account.Name FROM Contact limit 1';
Contact ct = database.query(query);
system.debug(ct.Account.Name);

 This returns the name of the Account. What's your code, and are you getting an error message?

 

Jeremy