function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Zarq IqbalZarq Iqbal 

How to find relationship names in ObjectPermissions and PermissionSet Objects

Just like Contacts is the name for the relationship between Contact and Account Object.
I need to perform a query which would fetch results from ObjectPermissions, PermissionSet and Profile
Best Answer chosen by Zarq Iqbal
sandeep sankhlasandeep sankhla
HI Zarq,

Below are the 4 child of these object and their relationship name please chcek and let me know if it helps you
 
Select (Select ParentId From SetupEntityAccessItems), (Select PermissionSetId From Assignments), (Select ParentId, SobjectType From ObjectPerms), (Select Field From FieldPerms) From PermissionSet p

 

All Answers

Zarq IqbalZarq Iqbal
The following query works fine:

SELECT Id, Name,
   (SELECT Id, LastName FROM Contacts WHERE LastName = 'Doe'),
   (SELECT Id, StageName FROM Opportunities)
FROM Account
WHERE Id IN (SELECT AccountId FROM Contact WHERE LastName = 'Doe')



But I need to do something like this:




Select Id,(Select Id from PermissionSets)from PermissionSet Where ParentID in(Select Id from ObjectPermissions)


This gives an error because the name of the relationship is not "PermissionSets". How do find all these relationships between these standard objects?
sandeep sankhlasandeep sankhla
Hi,

If you are using eclipse id then simply you can check everything in schema else you need to go to that object and check the field and relationship name..

Thanks,
sandeep
Zarq IqbalZarq Iqbal
Hi Sandeep,
I'm working with ObjectPermissions and PermissionSet objects here. They are not present in the cloud account schema builder or as objects over there. Unlike account and contact.
sandeep sankhlasandeep sankhla
Hi Zarq,

Please check using this..
Select (Select ParentId, SobjectType From ObjectPerms) From PermissionSet 
sandeep sankhlasandeep sankhla
HI Zarq,

Below are the 4 child of these object and their relationship name please chcek and let me know if it helps you
 
Select (Select ParentId From SetupEntityAccessItems), (Select PermissionSetId From Assignments), (Select ParentId, SobjectType From ObjectPerms), (Select Field From FieldPerms) From PermissionSet p

 
This was selected as the best answer
Zarq IqbalZarq Iqbal
Sandeep,

Thanks alot. This is helpful.

This is with one level of children. Like PermissionSet has these 4 children (SetupEntityAccessItems,Assignment,ObjectPerms,FieldPerms).

Now I want to go from Profiles to PermissionSet to it's children.

Also could you tell me how you found out the relationship names for these? 

SetupEntityAccessItems
Assignments
ObjectPerms
FieldPerms

I wasn't able to find them through the documentation which is ridiculously outdated!
sandeep sankhlasandeep sankhla
Hi Zarq,

As I mentioned above if you are using eclipse IDE for coding then there is schemna where you can easily find all things...

User-added image

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

You can get all thigs like it shows in eclipse..

Thanks,
Zarq IqbalZarq Iqbal
That is great. I'll try this definitely now.
But this doesn't seem to work upto two levels. I tried it.
As I mentioned from Profile --> PermissionSets-->ObjectPermission
 
sandeep sankhlasandeep sankhla
Yes, from profile you can not go ..this way its not possible...

Thanks
Zarq IqbalZarq Iqbal
Ok. So what is the approach to go multiple levels? I mean how do you mimic a nested join in SFDC?
sandeep sankhlasandeep sankhla
Hi,

You can simply make use of sets and maps to get tha data from multiple levels you need..

Collect all the profiles in a set then query on permission sets where profilID IN setsProfilrIDs..like this you can make maps and use as you want..

Thansk