Finding the SObjectType from the SObjectField
I don't believe this is possible currently. There's no methods on Schema.SObjectField of Schema.DescribeFieldResult that link back to the SObjectType that field belongs to.
I know this is a little old, but I was searching how to solve this problem and I couldn't find anything useful. This is how I solved it:
Type myObjectType = MyObject__c.myField__c.class;
String myObjectName = myObjectType.toString(); // You can use getName() as well
That code will give you the Type
of MyObject__c
class. Then you can use all the methods for Type
class in Apex like toString()
or getName()
to get the String name of MyObject__c
.
Please check Salesforce Type Class for more info.