Search code examples
salesforcesoql

How do I combine two objects in SOQL for a simple join? I just a list of users with their profile


I am trying to do a simple join between the user object and profile object. They are connected by ID User = profileID Profile = ID

This would be a simple query in SQL: select u.name, u.profileID, p.name, p.ID from Users Join Profile ON u.profileID = p.ID

I've tried the following and all I get are errors: Select User.name, (SELECT profile.name, profileID from Profile) from User

select name, profileID, userRoleId from User WHERE ProfileId IN (select name from Profile)

SELECT User.name, user.profileId (SELECT profile.name FROM Profile) FROM User Where User.ProfileId IN ( Select Profile.ID from Profile)


Solution

  • for following FK relationships, you use the compound name as the field to query, e.g.

    select name, profile.name from user
    

    See the SOQL relationships docs for more details.