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
JoannaJoanna 

SOQL Query with join?

I understand that SOQL is not SQL and that you have to use relationship queries rather than SQL joins.  I have a question regarding this, though.  I have a custom object "Project Fiscal Forecast", which has a Sub-Opportunity lookup field to another custom object - "Sub-Opportunity".  There is no master-child relationship between these two objects because "Sub-Opportunity is already a child of the Salesforce Opportunity object, and an object can only be in one master-child relationship.

So, my question is, can I query the Project Fiscal Forecast object and filter based on a field in the Sub-Opportunity object?  If so, is there some sample syntax for this somewhere?  I would have expected this to be a typical scenerio for a query.  I need to do this to display some data in an s-control.

Thanks!
RickyGRickyG
Joanna -

If you have a lookup to another object, you have a lookup relationship.  In terms of SOQL, lookup relationships are accessed with the same syntax as master-detail relationships, so you should not have a problem.

Hope this helps.

JoannaJoanna
Here is my query, which is not loading (I don't get a syntax error, it just fails to load the data in the S-Control).

"SELECT Forecast_GP__c, Forecast_Sales__c FROM Project_Fiscal_Forecast__c WHERE Account__c='"+aid+"'  AND Fiscal_Year_End__c = '"+CurrentFY+"' AND SubOpportunity__c.Forecasting_Stage__c IN ('Stage3', 'Stage4', 'Stage5')"

If I just have the following, the query runs fine:

"SELECT Forecast_GP__c, Forecast_Sales__c FROM Project_Fiscal_Forecast__c WHERE Account__c='"+aid+"'  AND Fiscal_Year_End__c = '"+CurrentFY+"'"

Anything obvious that I have wrong here?  I've also tried omitting the "SubOpportunity__c." part as well as changing it to an "=" instead of an "IN", but it will not run.  Any ideas?

Thanks so much.

Message Edited by Joanna on 10-30-2007 08:48 AM

RickyGRickyG
Have you tried changing the SubOpportunity__c.Forcasting_Stage__c to SubOpportunity__r.Forcasting_Stage__c? 

Hope this helps.

JoannaJoanna
That worked great.  Thanks!
vasuvasu

I want 2 write a query for eliminating duplications on Lead object using join query by comparing Email ID

 

I have 1lac records existed on Lead Object , How can I find duplicate records on  Lead

How can I do?

 

Help

 

Thanks

Vasu