3

Let's say I want to retrieve all the fields with master-detail for each objects for given PermSet. Why can we provide SObject type array instead of Ids? And how can I can retrieve SObjectType as well from second query?

     private static void getPermsetEntries(Id permSet) {
            List<String> entries = new List<String>();
            for(ObjectPermissions obp : [SELECT Id,
                            SObjectType, 
                            PermissionsRead, 
                            PermissionsEdit, 
                            PermissionsCreate, 
                            PermissionsDelete 
                        FROM ObjectPermissions 
                        WHERE ParentId = :permSet
                        ORDER BY SObjectType]) {
                entries.add(obp.SObjectType);
            }
            FieldDefinition[] entities = [SELECT DataType, 
                QualifiedApiName,
                EntityDefinitionId,
                EntityDefinition.DeveloperName
            FROM FieldDefinition 
            WHERE EntityDefinitionId in :entries
                AND Datatype LIKE 'Master-%' ];
            for(FieldDefinition def : entities) {
                    system.debug(def);
            }
        }

1 Answer 1

1

Why ... ?

We don't know, because the documentation doesn't tell us. Presumably, it's to make our lives easier when performing queries, because we don't have to query CustomObject or EntityDefinition before querying FieldDefinition.

And how can i can retrieve SObjectType as well from second query?

Use EntityDefinition.QualifiedApiName, as stated in the documentation.

2
  • Unfortunately, updated query (with EntityDefinition.QualifiedApiName as a field) returns only |DEBUG|FieldDefinition:{DataType=Master-Detail(Data Pipeline), QualifiedApiName=Data_Pipeline__c, EntityDefinitionId=01I1T000000lbkt, Id=000000000000000AAA, DurableId=01I1T000000lbkt.00N1T000007TEuZ}
    – pincet
    Commented May 19 at 17:18
  • sorry, my bad. was relying on devconsole logs - system.debug(def.EntityDefinition.QualifiedApiName + ':' + def.QualifiedApiName); it really works
    – pincet
    Commented May 19 at 17:38

You must log in to answer this question.

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