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
Phil WPhil W 

How to get the Object Describe from a Field Describe?

Our Salesforce app is structured so we have CRUD/FLS tests in our custom page controllers where needed. We have some utility methods that verify that the user has appropriate access to the objects (for CRUD) and fields (for FLS). These methods throw exceptions/return messages that explain the missing permission(s).

In the FLS test we pass in an array of necessary describe field results, obtained through the Schema namespace, e.g. Schema.SObjectType.Booking__c.fields.Client__c. The message should ideally explain that the user doesn't have the required permission (e.g. update) for the given field in the given object. However, it seems that the DescribeFieldResult doesn't provide a means to access the DescribeSObjectResult representing the containing object, so I can't get hold of the label for the object type to add that into the message.

Other than a massive refactoring to pass both the DescribeFieldResult and the DescribeObjectResult (this would be really ugly too), anyone know a way to navigate from the DescribeFieldResult to the "containing" DescribeSObjectResult?

Best Answer chosen by Phil W
Phil WPhil W
In the belief that this capability doesn't exist in the APIs (I can't find it) I have raised an idea (https://success.salesforce.com/ideaView?id=0873A000000lIJ8QAM) to add what I need. Please upvote it!