[SalesForce] How to get Standard and Custom Object List in Apex class

I am trying to get all Standard and Custom Objects name from Schema class in apex class. I need to remove all shared objects from the list.

Best Answer

Here is updated code that will give list of all objects excluding Share, history , Tag & feed. You can add extra condition to filter out other unnecessary sObjects.

List<string> SObjectList = new List<string>();

for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()){
   String name = objTyp.getDescribe().getName();
   // Exclude all the unwanted Sobjects e.g. History, Share etc..

 if((!name.containsignorecase('history') && !name.containsignorecase('tag')&&
    !name.containsignorecase('share') && !name.containsignorecase('feed')) || 
     name.toLowerCase().right(3) ==  '__c'){      
      SobjectList.add(name);
      System.debug( 'Name : ' + name);
  }

}
Related Topic