You need to sign in to do that
Don't have an account?
SOQL - Quering
Hi,
I have three custom objects: Aspirante__c, Vacante__c and Asignados__c. The Asignados__c object has a master-detail relationship with Aspirante__c and also has a master-detail relatonship with Vacante__c. I want quering from the Asignados__c object the name of Aspirante__c and the name of Vacante__c. I have the next query:
List<txmrecruitment__Aspirante__c> arbolvacs = [Select
(Select Name From txmrecruitment__Vacante__c.Vacantes_Aspirantes1__r)
From txmrecruitment__Asignados__c];
I am receiving the error:
Error: Compile Error: Didn't understand relationship 'txmrecruitment__Vacante__c' in field path. 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. at line 23 column 51
Thanks for any help!
That's definitely incorrect. Assuming I understand your statement correctly, your objects are:
Vacante__c <--- Asignados__c ---> Aspirante__c?
Assuming that is correct, you need the following query:
In a "many to many relationship" query, the child should be first, and the parents may be referenced from the child. use vacante__r.<fieldname> or aspirantes__r.<fieldname> to get the parent field values.
Thanks for reply.
I solved it with this query
List<txmrecruitment__Asignados__c> arbolvacs = [Select Vacante__r.Id_Vacante__c,Vacante__r.id,Vacante__r.Name,Aspirante__r.id,Aspirante__r.Name From Asignados__c];
I want to group by the name of Vacante with this query:
List<txmrecruitment__Asignados__c> arbolvacs = [Select Vacante__r.Id_Vacante__c,Vacante__r.id,Vacante__r.Name,Aspirante__r.id,Aspirante__r.Name From Asignados__c Group By Vacante__r.Name];
but I receive the next error:
Error: Compile Error: duplicate alias: Id at line 23 column 51
Do you know what is wrong?
Try aliasing your fields by specifying a replacement name after the field name in the query.
List<txmrecruitment__Asignados__c> arbolvacs = [Select
Vacante__r.Id_Vacante__c,
Vacante__r.id vacante_id, <-- aliased
Vacante__r.Name,
Aspirante__r.id Aspirante_id, <-aliased
Aspirante__r.Name
From Asignados__c Group By Vacante__r.Name];
You might need to do the same to the name fields.
Gabriel Alack
Contact Us - We Can Help!
Salesforce Superheroes
------------------------------
help@salesforcesuperheroes.com
www.salesforcesuperheroes.com
1-888-407-9578 x122