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

Retrieving lookup / reference object's fields from another object

Hi All,


I want to retrieve all fields of reference object/lookup object from another object.


I have one picklist  to select object, after selecting another picklists containing fields of object get populated.


So i want to retrieve all fields of reference/lookup object in fields picklist.


Please help me to retrieve those fields. Please share reference/sample code.




Best Answer chosen by Admin (Salesforce Developers) 
Bhawani SharmaBhawani Sharma
You will have to describe the selected object and get fields map. Iterate it and populate your picklist.
Map<String, Schema.SObjectField> M = Schema.getGlobalDescribe().get('account').getDescribe().fields.getMap();