+ Start a Discussion
Marcelo SerraMarcelo Serra 

soql between opportunity and order

I'm trying to query using a relationship between orders and opportunities.
I'm using opps to creat a job workflow to my agents and using orders to store my e-commerce data. I want to know how many opps become an order and know the conversion rate for that. 
I'm using this SOQL query, but i'm doing something wrong.
SELECT
  Name, Profession__c,
  (SELECT
    LastModifiedDate, CreatedDate, StageName
   FROM 
   Opportunity__r),
   (SELECT
     Date_Payment__c, Discount__c, Status, Final_Amount__c, Amount__c
    FROM
     Order__r)
FROM
  Account 
WHERE
  IsPersonAccount = true

 
Best Answer chosen by Marcelo Serra
Alaric WimerAlaric Wimer

The "__r" refers to custom objects. Assuming, that your Order and Opportunity objects are not custom objects, you need to remove the "__r". In addition, nested queries in SOQL use the plural version of the Object. So, Opportunity becomes Opportunities and Order becomes Orders. 

 

Here's what I would try: change Opportunity__r to Opportunities and Order__r to Orders.

 

SOQL query would look something like this instead:

 

SELECT
  Name, Profession__c,
  (SELECT
    LastModifiedDate, CreatedDate, StageName
   FROM 
   Opportunities),
   (SELECT
     Date_Payment__c, Discount__c, Status, Final_Amount__c, Amount__c
    FROM
     Orders)
FROM 
  Account 
WHERE
  IsPersonAccount = true