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
joseph keuler 1joseph keuler 1 

SOQL to accommodate objects

So I have a custom object standard controller and I want to auto-populate a field on a form from the users account record.

In preparation to build my controller I need a valid SOQL statement and I'm getting nested semi-join sub selects error on the Workbench.

I'm getting errors on the SOQL query:
 
select agency_acronym__C from account 
   where id in (SELECT AccountId FROM Contact 
   where id in (SELECT ContactId FROM User 
   where id in (SELECT OwnerId FROM Application__c)))


if this where in SQL Syntax I'd just use joins. I'm new to SOQL
 
select agency_acronym__c from 
account inner join contact on account.accountID = contact.accountID
inner join user on contact.contactid = user.contactid
inner join application__c on user.id = application__c.ownerid

Thanks,
Joe
Swayam@SalesforceGuySwayam@SalesforceGuy
Hi Joseph,

Can please take a screen shot of which error you are gettin in work bench

--
Thanks,
Swayam
joseph keuler 1joseph keuler 1
I got a litte further and I'm getting a new error:
this is my SOQL statement: 
SELECT Agency_Acronym__c FROM Account WHERE Id IN (SELECT owner.Contact.AccountId FROM Application__c)

This is my new error from the query edtior in the debug window:
FROM Account WHERE Id IN (SELECT owner.Contact.AccountId FROM Application__c)
                                 ^
ERROR at Row:1:Column:59
Didn't understand relationship 'Contact' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

 
Ansh CoderAnsh Coder
Hi,
The following query will return a record of object 'Application__c' not the value of 'Accountid'.
SELECT owner.Contact.AccountId FROM Application__c

Try the following code.
application__c app=[SELECT owner.Contact.AccountId FROM Application__c];
account a=[SELECT Agency_Acronym__c FROM Account WHERE Id =: app.owner.Contact.AccountId];

Hope this helps you.

Thanks,
Anand Sharma
joseph keuler 1joseph keuler 1
I tried the first query in the Query Editor and still get the parsing error.  
SELECT owner.Contact.Accountid FROM application__C