You need to sign in to do that
Don't have an account?

How to query detail records from SOQL
Hi.
I have a custom object (TargetX_SRMb__Application__c) It has a relationship to Contact defined in WSDL by:
<complexType name="TargetX_SRMb__Application__c">
<complexContent>
<extension base="ens:sObject">
...
<element name="TargetX_SRMb__Contact__c" nillable="true" minOccurs="0" type="tns:ID"/>
<element name="TargetX_SRMb__Contact__r" nillable="true" minOccurs="0" type="ens:Contact"/>
However, when I run SOQL test as:
Contact contact = [SELECT c.Id, c.lastName, (Select CreatedDate FROM TargetX_SRMb__Contact__r) FROM Contact c]
I get error:
I also tries adding a "s" as follows: Same error.
Contact contact = [SELECT c.Id, c.lastName, (Select CreatedDate FROM TargetX_SRMb__Contacts__r) FROM Contact c]
Is this not the correct syntax to query child records from a custom object?
Thanks in advance,
Jon
I have a custom object (TargetX_SRMb__Application__c) It has a relationship to Contact defined in WSDL by:
<complexType name="TargetX_SRMb__Application__c">
<complexContent>
<extension base="ens:sObject">
...
<element name="TargetX_SRMb__Contact__c" nillable="true" minOccurs="0" type="tns:ID"/>
<element name="TargetX_SRMb__Contact__r" nillable="true" minOccurs="0" type="ens:Contact"/>
However, when I run SOQL test as:
Contact contact = [SELECT c.Id, c.lastName, (Select CreatedDate FROM TargetX_SRMb__Contact__r) FROM Contact c]
I get error:
Error: Compile Error: Didn't understand relationship 'TargetX_SRMb__Contact__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 |
I also tries adding a "s" as follows: Same error.
Contact contact = [SELECT c.Id, c.lastName, (Select CreatedDate FROM TargetX_SRMb__Contacts__r) FROM Contact c]
Is this not the correct syntax to query child records from a custom object?
Thanks in advance,
Jon
1.Go to this object TargetX_SRMb__Contact
2.click on look up /master detail field to Contract
3.Check relationshipname
4.Then append __r to relationship name
Thanks asish1989. The relationship name is Application so if I append __r to this I still get same error.
@isTest
private class TestClass {
static testMethod void validate() {
Contact c = [SELECT Id, lastName, (Select Id FROM Application__r) FROM Contact ];
}
}
Master-Detail Options
Contact c = [SELECT Id, lastName, (Select Id , Eform_Type__c FROM USD_Eform__r) FROM Contact ];
Contact c = [SELECT Id, lastName, (Select Id FROM Application__r) FROM Contact ];
if Application__c is a object from manged package then append package prefix name to that relationship name.
for example write package_prefix_Application__r in stead of Application__r.
SELECT c.Id, c.lastName, (Select CreatedDate FROM TargetX_SRMb__Applications__r) FROM Contact c
Attached eclispe screen shot
http://www.cloudforce4u.com/2013/06/sometimes-we-need-list-of-all-child.html