Listing data from a table with a field matching a logged in user related field

My scenario is as follows:

  • User table has a field “Related_Company”, which is an object relation field to Company table
  • Course table has a field “Related_Company”, which is an object relation field to Company table

I want to list all courses related to the Company that the User is also related to.

In the REST console I can do this by using the objectId of the Company, but in UI Builder it does not seem that related fields are visible/part of the current logged in user object.

So, how can I get a list of related objects? Do I have to split this in two DB queries, and retrieve first the company Id related to the user, then use the same Id to get the Courses that I want?

Or is there a simpler way?

To answer myself, in case someone else has the same situation, I solved this by getting the relation this way:

Company.Users[Related_Company].objectId=‘…’

Not sure if this is the best way of doing it, but at least it is A way…