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
José RiveroJosé Rivero 

help to write an SOQL query

Hello, 

I want to show my Scheduled Revenue by account, I have 3 objects with these variables :

- Account : account_name , account_id
- Opportunity : account_id , stage , opportunity_id
- ORSchedule_c : opportunity_id , expected_revenue , date

my goal is to return : account_name , stage , exêcted_revenue , date

Can someone help me with these ?

Thank you ! 

José
Alain CabonAlain Cabon
The problem is to have the right relationship name ( opportunity__r by default ).

You can always get the parent, the parent of the parent, etc ... from an object ( five levels can be specified in a child-to-parent relationship ).
 
select opportunity__r.account.name, opportunity__r.stage, expected_revenue, mydate__c, createddate
from ORSchedule__c

It is not "account__r" because it is a standard object and there is not "__r" here. It is just opportunity__r.account.
José RiveroJosé Rivero
got it thank you !
sachinarorasfsachinarorasf
Hi José,

Please go through the below link:

https://developer.salesforce.com/forums/?id=906F0000000kIFGIA2

And go to the bottom of the page to see the SOQL query.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Sachin Arora
www.sachinsf.com
Alain CabonAlain Cabon
The important standard objet for the name of the relationship is the parent (here opportunity). That could be : myobject__r.account__r but it is opportunity__r.account. ( opportunity.account. )