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
Kam.ax1015Kam.ax1015 

REST API - Retrieving child records

Hello,

 

Let's say we retrieve a specific account using

/services/data/v22.0/sobjects/Account/0015000000afWuJAAU

 

How to retrieve child records for this specific account? One entity can have 0..multiple child relationships.

e.g.something like following should retrieve Contacts or Cases for the account record...

/services/data/v22.0/sobjects/Account/0015000000afWuJAAU/Contacts
/services/data/v22.0/sobjects/Account/0015000000afWuJAAU/Cases

 

I am sure this is a dumb question but could not find the answer in the docs. Also using REST explorer but can not figure out how to get child records?

 

Please help.

 

Thanks,

Kam

 

Best Answer chosen by Admin (Salesforce Developers) 
dkadordkador

REST is much more than URI - read up on it at wikipedia if you like.  The core concept is based around identifying individual resources.  In this case, you need to use our query resource.

 

What you're asking for makes sense, but it's not a resource we've built.

All Answers

cloudcodercloudcoder

Have a look at the Quick Start section of the REST API docs (http://www.salesforce.com/us/developer/docs/api_rest/index.htm) . Step 4, Get a list of Fields, gives you an example of Child Relationships which is what you want.

 

 

Kam.ax1015Kam.ax1015

Thanks for your prompt help.

 

But let's say there is an acocunt 

/services/data/v22.0/sobjects/Account/0015000000afWuJAAU

 

and there is a child object relationship to it e.g. AccountHistory , so what would the synatx be to get Account History for this particular (0015000000afWuJAAU) account? I tried something like but does not work

/services/data/v22.0/sobjects/Account/0015000000afWuJAAU/AccountHistory

 

 

Thanks,

Kam

 

dkadordkador

You'll need to do a query with a nested relationship for this.

 

select id, (select id from accounthistory) from account

 

There's no corresponding resource for child records.

Kam.ax1015Kam.ax1015

But that means most of the AJAX calls will end up being SELECT query rather than following true REST philosophy....

 

Thanks,

Kam

dkadordkador

You do a GET request to /services/data/vXX.X/query?q=your_query_here

 

There's nothing unRESTful about that.

Kam.ax1015Kam.ax1015

My understanding of REST was that it goes by URI and you can drill down using that. Otherwise it become just json based APIs. But I could be wrong.

 

I truely appriciate your help.

 

Thanks,

Kam

dkadordkador

REST is much more than URI - read up on it at wikipedia if you like.  The core concept is based around identifying individual resources.  In this case, you need to use our query resource.

 

What you're asking for makes sense, but it's not a resource we've built.

This was selected as the best answer
jhurstjhurst
Just an update on this older thread, relationships can now be accessed through Friendly URLs like described in the original post.