[SalesForce] wrong with the relationship

I'm trying to use SOQL 'relationships' between two tables.

I follow this example and it works fine:

SELECT Account.Name, (SELECT Contact.Name FROM contacts) FROM Account

from: https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html

I attempt what I think is equivalent on our Org:

SELECT Case.Postcode_and_number__c, (SELECT SocialPersona.Id FROM SocialPersonas) FROM Case

But I get:

INVALID_TYPE: (SELECT SocialPersona.Id FROM SocialPersonas) FROM Case
^ ERROR at Row:1:Column:67 Didn't understand relationship
'SocialPersonas' 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.

Could someone please tell me what I'm missing here? Thank you.

Best Answer

I don't think there is a child relationship SocialPersonas available.

Follow these steps, to see the ones available

  1. Log in to the Developer Workbench
  2. jump to "Standard & Custom Objects"
  3. Choose the object "Case"
  4. Open the "Child Relationships" folder

To find the API name you need to use in your SOQL query:

  1. Open the child relationship you want
  2. See the API name of the relationship you need to use in your SOQL next to "relationshipName"

For example, for the child relationship CaseMilestone, the relationshipname is: "CaseMilestones", in a SOQL query I would use it like this: [SELECT Id, (SELECT Id FROM CaseMilestones) FROM Case];. For custom objects you would see the __r appended to the child relationshipname right there, just as you would need to use it a SOQL query.

enter image description here

Related Topic