I have the following code working:

SELECT of_Loans__c, Id, ( SELECT id FROM Loans__r WHERE MtgPlanner_CRM_Status__c = 'Closed')  FROM Contact

After some time tinkering around, I was able to access the information of the loan related list (on the Contact page) using the '__r' extension. The above SOQL query does as I want it:

Successful SOQL query

However, I did this in a sandbox environment which may not have the same relationships between objects as I have in live.

A similar SOQL query (in live):

SELECT of_Closed_Loans__c, Id, ( SELECT id FROM Loans__r WHERE MtgPlanner_CRM__Status__c = 'Closed')  FROM Contact

renders the following error: didn't understand relationship 'Loans__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names

Both environments have Contacts with a related list to the Loan object; I do not know what might I need to tweak on the live env. to replicate the results of the successful first sandbox env.

Any suggestions are appreciated!

  • 1
    You should check the child relationship name of your relationship field on Loan__c in your prod/live environment. Given your error, it's quite likely to be something other than Loans.
    – Derek F
    Jun 5, 2019 at 19:55
  • 1
    Specifically, since you're using Dev Workbench, go to Info > Standard & Custom Objects. Select Contact from the Object drop-down. Expand the Child Relationships folder, and scroll down to Loan__c.[your contact lookup or M/D field on Loan]__c, and expand that. The relationshipName will be shown there. Jun 5, 2019 at 20:06
  • THANK YOU!!!!!!
    – Peabrain
    Jun 5, 2019 at 21:00


Browse other questions tagged .