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
pooja kasliwalpooja kasliwal 

Display Type Of Object

Hello Everyone,
                       I want to display the relationship between two objects(MD or Lookup) on visualforce page and  If i choose one object from one picklist then it shoul show picklist of its all related obejct and their relationship type  (MD or Lookup) on vf.how can i achieve it??
  Thanks in advance..
AshlekhAshlekh
Hi,

You need to see this link where all method has describe to get the description of objects.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject_describe.htm

Here is example how to use those method.

By this you can get all object.
Map<String, Schema.SObjectType> GlobalMap = Schema.getGlobalDescribe();
for (Schema.SObjectType Obj : GlobalMap.values()) {
    Schema.DescribeSObjectResult ObjDesc = Obj.getDescribe();
    system.debug('Object Name: ' + ObjDesc.getName());
}

Here is another example to get the child relation ship
// sObject types to describe
String[] types = new String[]{'Account','Merchandise__c'};
// Make the describe call
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(types);
System.debug('Got describe information for ' + results.size() + ' sObjects.');
// For each returned result, get some info
for(Schema.DescribeSobjectResult res : results) {
    System.debug('sObject Label: ' + res.getLabel());
    System.debug('Number of fields: ' + res.fields.getMap().size());
    System.debug(res.isCustom() ? 'This is a custom object.' : 'This is a standard object.');
    // Get child relationships
    Schema.ChildRelationship[] rels = res.getChildRelationships();
    if (rels.size() > 0) {
        System.debug(res.getName() + ' has ' + rels.size() + ' child relationships.');
    }
}


-Thanks
Ashlekh Gera