0

I expected the following query is valid:

SELECT ID, Subject, Type, (SELECT Field, OldValue, NewValue FROM CaseHistories)
FROM Case

But I get Didn't understand relationship 'CaseHistories' error. I can query SELECT Field, OldValue, NewValue FROM CaseHistories in a separate request.

Is this possible to retrieve cases and their histories in one query?

edelrabe
  • 789
  • 6
  • 22
  • 1
    you can always use describe call to check the relationship name http://salesforce.stackexchange.com/a/117054/18731 – Ratan Paul May 11 '16 at 08:54

1 Answers1

7

The child history relationship name is called "histories".
Try the following query:

SELECT ID, Subject, Type, (SELECT Field, OldValue, NewValue FROM Histories)
FROM Case
Marc Zaharescu
  • 1,688
  • 12
  • 31
  • thanks Mark, where can I find how specific relationship is called? – edelrabe May 11 '16 at 09:51
  • 1
    I found Relationship Name in Force.com IDE, is there any other tool where I can quick check the name? Maybe I can find it in Salesforce UI? Salesforce Schema Builder doesn't have one. – edelrabe May 11 '16 at 09:54
  • 1
    You can identify parent-child relationships by viewing Entity Relationship Diagrams (ERD) or by examining the enterprise WSDL for your organization. But probably the most reliable method for identifying relationships is to execute a describeSObjects() call. You can use the AJAX Toolkit to quickly execute test calls. – Marc Zaharescu May 11 '16 at 10:01