0

I am writing a query on an object that has a custom relationship to another. I wrote This in the query editor:

Select 
OrderNumber, 
ImportingBroker__r.Company_Name__c,
ImportingBroker__r.street,
ImportingBroker__r.city,
ImportingBroker__r.state,
ImportingBroker__r.countryCode
from Order where ordernumber ="*ordernumber*"

In the query editor, this executes fine and returns data.

my apex function looks like this:

Order o = [
Select 
    OrderNumber, 
    ImportingBroker__r.Company_Name__c,
    ImportingBroker__r.street,
    ImportingBroker__r.city,
    ImportingBroker__r.state,
    ImportingBroker__r.countryCode
    from Order where ordernumber ="*ordernumber*"] ;

But in the apex editor, it's telling me that there is no relationship "ImportingBroker__r" on the "Order" object, which makes no sense. There is a relation ship named ImportingBroker__c set up, and it does work when executed in the query editor. so whats the deal?

4
  • double quotes in Apex are not supported ?
    – cropredy
    Commented Feb 19, 2022 at 4:39
  • @cropredy that was a typo in stack exchange. The actual code is syntactically correct enough to run in the query editor.
    – DrJaul
    Commented Feb 19, 2022 at 5:12
  • 3
    Did you deploy this relationship field to a new org (and are getting this error in that new org)? If so, did you set the FLS for the field in the new org? Field permissions are stored in profiles and/or permission sets, not with the field. So if you didn't deploy a profile (which has historically been hard to do) or a permission set, nobody in the new org would have permission to read/write it. Not even System Administrators (though you would be able to see the field exists when looking at the object's fields in the object manager).
    – Derek F
    Commented Feb 19, 2022 at 14:58
  • @DerekF nope, the relationship alredy existed in the org, it just wasn't in use. I made use of the relationship in an existing Apex class that was working just fine without any __r references. The only thing I changed to make this work was the version of the SF API being used by the apex class, which you can change from a dropdown at the top of the apex class editor
    – DrJaul
    Commented Mar 23, 2022 at 15:49

1 Answer 1

-1

Turns out the answer to my issue was the API version of apex was set to 45. The '__r' relationship functionality Only works for API versions 49+

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Feb 22, 2022 at 16:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .