You need to sign in to do that
Don't have an account?
Hartley
SOQL query to get custom field in standard object from Custom Object
Hey,
I have a Custom object (custom_object__c) with a Lookup field for (Contact) from which I would like to get a field or custom field from a standard object (ie. Contact). If I understood correctly I then need to do a Child - Parent relationship which is in the form of dot notation.
So here is my code:
public static List<custom_object__c> getStudents(){
LIST<custom_object__c> students = [SELECT
Id,
Name,
Contact__r.custom_field__c,
custom_object__c__custom_field_1,
custom_object__c__custom_field_1
FROM custom_object__c
LIMIT 100
OFFSET 0];
return students;
}
And here is the error message:
Didn't understand relationship 'Contact__r' 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.
Any explanation is greatly appreciated, thank you.
I have a Custom object (custom_object__c) with a Lookup field for (Contact) from which I would like to get a field or custom field from a standard object (ie. Contact). If I understood correctly I then need to do a Child - Parent relationship which is in the form of dot notation.
So here is my code:
public static List<custom_object__c> getStudents(){
LIST<custom_object__c> students = [SELECT
Id,
Name,
Contact__r.custom_field__c,
custom_object__c__custom_field_1,
custom_object__c__custom_field_1
FROM custom_object__c
LIMIT 100
OFFSET 0];
return students;
}
And here is the error message:
Didn't understand relationship 'Contact__r' 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.
Any explanation is greatly appreciated, thank you.
i got it, try this query for get student(contact lookup) fields , campus(account lookup) fields from StudentTermRegistration__c
let me inform please if it work and mark this question as solve ;)
All Answers
you can query contact lookup fields from custome_object__c by this query
If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer. ;-)
Thanks for the quick responses.
So I'm assuming the part I was missing was the Contact__c within my SELECT statement, however I've updated my query with your feedback and I'm still getting the same error.
It's still unable to understand relationship Contact__r . Is there maybe a setting or configuration I must make to the Object in order for this to work ? Or am I misunderstanding the relationship between the two Objects ?
Thanks again.
--------------------
Fields
--------
Label = Student
API name = Student__c
Type = Lookup(Contact)
Label = Campus
API name = Campus__c
Type = Lookup(Account)
Label = Program Title
API name = Program_Title__c
Type = Formula (Text)
There are other fields but you get the point. This also ties into another question of doing multiple custom relationships on different Objects. Thanks a lot again ! Let me know if you require any further information.
[SELECT Id, Name,Student__r.custom_field__c FROM StudentTermRegistration__c LIMIT 100 OFFSET 0];
Fields
--------
Label = Student
Name = Student__c
Type = Lookup(Contact)
Label = Campus
Name = Campus__c
Type = Lookup(Account)
Label = Program Title
Name = Program_Title__c
Type = Formula (Text)
Which is why the previous provided answer will not work since the Object is StudentTermRegistration__c and the fields for that object are what is listed above.
Also to be clear what I want to do is get certain fields from the Contact Object from my Custom child object StudentTermRegistration__c and eventually get certain data from the Account Oject from the same custom object. The fields listed above demonstrate the references or Lookups of the Objects from my custom object.
i got it, try this query for get student(contact lookup) fields , campus(account lookup) fields from StudentTermRegistration__c
let me inform please if it work and mark this question as solve ;)
Thanks a lot, that did the trick !!
object how i
did