Retrieve Records filtering on an Entity Reference field using OData

I ran into a problem today trying to retrieve records filtering on an Entity Reference field using the OData endpoint.  Thanks to Jim Daly for helping me. An Entity Reference field contains several properties and Id is one of the its properties.  Usually when you are filtering using OData, all you have to do is use the keyword $filter, the search field, operator and the value.

For example, to retrieve all the accounts where address1_city equal Redmond, you’ll do the following:

 /AccountSet?$filter=Address1_City eq 'Redmond' 

 

However to retrieve from an Entity Reference field is little bit different.  To access the properties in an Entity Reference field, you just need to use the forward slash “/” and then follow by the property name.

 

For example, to retrieve all the accounts where primarycontactid equal to {guid}, you have to do the following:

 

 AccountSet?$filter=PrimaryContactId/Id eq (Guid'567DAA8F-BE0E-E011-B7C7-000C2967EE46') 

I hope this help in your next project.