1

I have two objects Accounts and Invoices. Invoices used to have a lookup relationship to Accounts called "Otter_FFA_Sold_To__c". This relationship was changed to Master relationship. So now, the owner of the invoices will be owner of the account because Account is now the parent.

My question is because due to this change now some queries are failing like this one:

  Select Owner.Name c,Invoice_Amount__c from Otter_FFA_Invoice_New__c

I'm getting the error "Didn't understand relationship 'Owner' in field path." I know that it's because of this change. However I don't know which is the best approach to get the owner of the child record in a query.

My query is a little bit more complex than that one but if someone can help how can I achieve this I will appreciate it.

The query that it's failing is this one:

 Select Owner.Name c,Sum(Invoice_Amount__c)s from Otter_FFA_Invoice_New__c where (Qad_Entity__c=:ent) and (Otter_FFA_Effective_Date__c >=:CurrentMonthStartDate.toStartOfMonth() and Otter_FFA_Effective_Date__c <=:Effective.Otter_FFA_Effective_Date__c) Group By Owner.Name Limit 500 

2 Answers 2

5

The owner is the owner of the account; this implicitly removes the OwnerId field on the child object entirely (if you change it back to a lookup field, it will come back). So, you just need to change your query to compensate for this behavior:

Select Account__r.Owner.Name c, Sum(Invoice_Amount__c)s
from Otter_FFA_Invoice_New__c 
where Qad_Entity__c=:ent and 
      Otter_FFA_Effective_Date__c >=:CurrentMonthStartDate.toStartOfMonth() and
      Otter_FFA_Effective_Date__c <=:Effective.Otter_FFA_Effective_Date__c
Group By Account__r.Owner.Name 
Limit 500 
1
  • Thanks for your answer. This is exactly what I was looking for. It works beautifully...!!!
    – MANUELAN00
    Mar 29, 2016 at 2:41
2

You should just be able to look up at the Account's owner like(depending on api name of the master detail account relationship):

Select Account__r.Owner.Name c,Sum(Invoice_Amount__c)s 
  from Otter_FFA_Invoice_New__c where (Qad_Entity__c=:ent) 
   and (Otter_FFA_Effective_Date__c >=:CurrentMonthStartDate.toStartOfMonth() 
   and Otter_FFA_Effective_Date__c <=:Effective.Otter_FFA_Effective_Date__c) 
 Group By Owner.Name Limit 500 
1
  • Thanks for your answer. This is exactly what I was looking for. It works beautifully...!!!
    – MANUELAN00
    Mar 29, 2016 at 2:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .