0

I'm trying to understand how to query using relationships, I'm facing an issue I don't understand,

Here is what I'm trying to resolve :

enter image description here

I'm trying this, but it seems to be wrong.. Can you help me ?

enter image description here

I can't see any Certification__r object in my environment ... Is that why I got this issue :

                          Certification_Attempt__c.Certification__r.id
                          ^ 

Didn't understand relationship 'Certification__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.

If you have an idea, I'm lost...

Thanks

Edit : A Schema Builder picture.. Doesn't it show there is no relation between the Certification, and the attempt ?

A Schema Builder picture

------------FINAL EDIT - PROBLEM SOLVED ------------

Ok, there is plenty of things I didn't understand well, and I've been able to understand reading docs and working on it ;

I'll post my work for next people having troubles with this to understand, hope it will help !

First, I didn't look so well to the Certification Application Schema and to the Schema Builder :

enter image description here

enter image description here

And my query and the results :

enter image description here

enter image description here

Thanks to you, helpers !

2
  • 1
    If you want to know whether the relationship exists, just go to the object definition of your Certification_Attempt__c object. There you will see the fields on that object, including any relationship fields like lookup or master-detail. Jun 22 '18 at 20:06
  • Humm... Sometimes I don't really understand how it works : What about the FirstName and LastName, in the Account object ? The only field required for an insert acc; is LastName. The Name field, however, is the only that appears in both schema builder and object manager. And I understand that Name is an automatic field given by : Salutation + FirstName + LastName But where can I see, and change, the FirstName or LastName fields ? That's one thing I didn't get yet. Thanks for your help, anyway !! Jun 26 '18 at 15:14
2

You have to understand child-to-parent relationships on queries. Check this article for further understanding.

Do you have a Certification__c custom object on the org, which is as a parent of Certification_Attempt__c, right? If so then you have to make just:

Certification__r.id on the query.

EDIT

You have also to remove from query the Certification_Attempt__c field from query, as you already are querying that object.

The full correct query would be:

List<Certification_Attempt__c> oldCertAttempts = [Select Id, Name, Certification_Element__r.Id, Certification_Element__r.Name, Contact.Name, Contact.Account.Name
                                              From Certification_Attempt__c
                                              Where Status__c = 'Scheduled'];
2
  • I tried it, but it's not working .. It seems to me, that the relationship is missing ! I mean, I have : Certification__c object and Certification_Attempt__c object But no relation installed between them ! I'll edit my first message in order to have a schema builder picture to show it. Jun 22 '18 at 15:04
  • 1
    Check my updated answer. Jun 22 '18 at 15:30
2

When you use a relationship name in a query, you must use the relationship names without the __c. Instead, append an __r (underscore underscore r).

See the relevant sfdc help page:

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_and_custom_objects.htm

This means the __r is probably correct but you need to remove the Certification_Attempt__c. prefixes as you don't need to specify the object name for each field.

1
  • I'll look (again) at the salesforce doc, thanks ! But I just tested just to request Certification__r.id, and it doesn't work. I got this error : " Certification__r ^ ERROR at Row:2:Column:59 No such column 'Certification__r' on entity 'Certification_Attempt__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names." (thanks, tho !) Jun 22 '18 at 15:10
1

I think its

   Certification_Attempt__r.certification__c

If certification attempt is a child and certification is parent

You can access certification name like this

Certification_Attempt__r.certification__r.Name

Please check below posts:

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships.htm

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.