4

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.

  • Have you tried adjusting your subquery to read SELECT SocialPersona.Id FROM SocialPersonas__r. Try appending the '__r' – Chris Duncombe Oct 19 '14 at 12:26
  • Thanks for the reply. I have tried that with 1 and 2 underscores. INVALID_TYPE: (SELECT SocialPersona.Id FROM SocialPersonas_r) FROM Case ^ ERROR at Row:1:Column:67 Didn't understand relationship 'SocialPersonas_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. – JayDee Oct 19 '14 at 12:33
  • I've experienced some weird things around SocialPersona metadata, i'm not sure if it's possible. – Samuel De Rycke Oct 19 '14 at 13:29
  • "Hi" from the Hot Network Questions list. This is up there with the ones we usually see from Arqade :-) – Philip Kendall Oct 19 '14 at 18:43
10

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

| improve this answer | |
0

Hello you just two updates in query. 1. You can update the Relationship API in query (Like :use SocialPersonas__r instead of SocialPersonas). 2. and second at the alias in inner query user the object api name (like : use SocialPersona__c.Id instead of SocialPersona.Id)

SELECT Case.Postcode_and_number__c, (SELECT SocialPersona__c.Id FROM SocialPersonas__r) FROM Case

Thanks Satya

| improve this answer | |
  • Socialpersona is a standard object and hence would not be represented by a __r relationship – cropredy Oct 19 '14 at 22:58
  • Thanks Satya. I just tried the above and get: INVALID_TYPE: (SELECT SocialPersona__c.Id FROM SocialPersonas__r) FROM Case ^ ERROR at Row:1:Column:70 Didn't understand relationship 'SocialPersonas__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. – JayDee Oct 20 '14 at 12:13
  • If it is standard object then don't need to append "__r" with relationship object, write the query with the help of eclipse or workbench. You will over come this problem. – Satyendra Rawat Oct 21 '14 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.