+ Start a Discussion
Ratheven SivarajahRatheven Sivarajah 

How to query a custom object through a standard object using a soql

Hey Everyone, I am trying to do a query call to a child object and the parent object is a standard object. I am getting a error. Please help.
Thank you in Advance.

--------------This works standard object--------------
List<case> cas = [SELECT AccountId,CreatedById FROM case WHERE Id ='50005000005ym2OAAQ' ];

--------------This works custom object-------------------------
List<Quote_Request__c> req =[SELECT name FROM Quote_Request__c WHERE Id='a1505000000qzRjAAI'];

---------------This does not work---------------------------------
List<case> cases =[SELECT AccountId,CreatedById,(SELECT name FROM case.Quote_Request__c) FROM case WHERE Id ='50005000005ym2OAAQ']
AnkaiahAnkaiah (Salesforce Developers) 
Hi Ratheven,

Do you have relationship between case and custom object?

If yes then try with below
List<case> cases =[SELECT AccountId,CreatedById,(SELECT name FROM Quote_Request__r) FROM case WHERE Id ='50005000005ym2OAAQ']

If this helps, Please mark it as best answer.

Kim AshleyKim Ashley
Log in to your Salesforce account. Click Setup at the upper-right corner. Under the Build section, click Create and select Objects. To create a custom object, click New Custom Object. Enter the name of the Custom Object in Label, Plural Label, and Object Name. Select the Launch New Custom Tab Wizard after saving this custom object check box and click Save. To select an icon for the tab, click the Search icon and click Save. To make the Custom Object available to Profiles, select the appropriate option and click Next. Choose the custom apps for which the new Custom tab is required and click Save.    https://www.prepaidgiftbalance.vip