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
osf_teamosf_team 

How to get description of Salesforce objects

Hi,

Is there any way by which I can get the description of all the Salesforce objects.

I have created a UI where user can see all the Salesforce objects. Now what I want is, when the user selects any of the objects, the description of that object should be dispayed below the objects list.
For example, as per the Salesforce documentation, the description of "Account" object is "An individual account, which is an organization involved with your business (such as customers, competitors, and partners)". So, whenever the user selects the Account object, this description should be visible to him.

I've tried using describeSObject/describeGlobal calls of SOAP API, but it does not return the description of object. Is there any other way (may be using Metadata API or any other API), using which I can get it?

Regards
Shalindra Singh
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that wil help u
<apex:page controller="ExtractSobject">
<apex:form >
   <apex:pageblock >
     <apex:pageblocksection >
       <apex:pageBlockSectionItem >
         <apex:outputlabel value="Select Object"/>
          <apex:selectList value="{!Selectedobject }" size="1">
            <apex:selectoptions value="{!Selectedobjnames}"></apex:selectoptions>
            <apex:actionSupport event="onchange" rerender="a"/>
         </apex:selectList>
       </apex:pageBlockSectionItem>
      
     <apex:pageBlockSectionItem >
      <apex:outputPanel id="a">
         <apex:outputLabel value="Object Fields" ></apex:outputLabel>
             <apex:selectList value="{!Sf}" size="1"> 
                   <apex:selectOptions value="{!SelectedobjFields}" />
             </apex:selectList>
      </apex:outputPanel>
     </apex:pageBlockSectionItem>
     
     
   </apex:pageBlockSection>   
  </apex:pageblock>
 </apex:form>
 
</apex:page>
 
public with sharing class ExtractSobject
{
    public String Sf{get;set;}
    public String Selectedobject { get; set; }    
  
        public List<SelectOption> getSelectedobjnames()
        {
            List<Schema.SObjectType> obj = Schema.getGlobalDescribe().Values();
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('--Select Object--','--Select Object--'));
            for(Schema.SObjectType st : obj)
            {
                if(Selectedobject == null || Selectedobject=='' )
                {       
                    Selectedobject = st.getDescribe().getName();
                }
                options.add(new SelectOption(st.getDescribe().getName(),st.getDescribe().getName()));
            }
            return options;
        }
       
        public List<SelectOption> getSelectedobjFields()
        {
            SObjectType objTyp = Schema.getGlobalDescribe().get(Selectedobject);
            DescribeSObjectResult objDef = objTyp.getDescribe();
            Map<String, SObjectField> fields = objDef.fields.getMap();

            Set<String> fieldSet = fields.keySet();
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('--Select Object--','--Select Object--'));
            for(String s:fieldSet)
            {  
                SObjectField Sobjfields = fields.get(s);
                DescribeFieldResult selectedField = Sobjfields.getDescribe();                 
                options.add(new SelectOption(selectedField.getName(),selectedField.getName()));
            }
            return options;
        }
}

Please let us know if this will help u

Thanks
Amit Chaudhary