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
ForceRookieForceRookie 

How to get all Standard and Custom Objects only?

How can I get all Objects except the System Objects in SF?

Here's my code. But I need to revise it to get only the needed Objects.

@AuraEnabled
	public static List<SelectOption> fetchAllObjects(){
        Set<String> listObjs = new Set<String>();
        for(MyCustomSettings__c cs : [Select Id, Objects__c From MyCustomSettings__c]){
            listObjs.add(cs.Objects__c);
        }

		List<SelectOption> objList = new List<SelectOption>();
        Set<String> csObjNames = new Set<String>();
        Map<String, String> mapName = new Map<String, String>();
        Map<String, String> mapLabel = new Map<String, String>();
		for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()){
            System.debug(objTyp.getDescribe().getLabel());

            if ( objTyp.getDescribe().isCreateable()) {
                csObjNames.add(objTyp.getDescribe().getLabel());
                    mapName.put(objTyp.getDescribe().getLabel(), objTyp.getDescribe().getName());
                    mapLabel.put(objTyp.getDescribe().getName(), objTyp.getDescribe().getLabel());
            }
		}

        List<String> objNamesCast = new List<String>();
        objNamesCast.addAll(csObjNames);
        objNamesCast.sort();

        for(String s : objNamesCast){
            String objTypeName = mapName.get(s);
            String objTypeLabel = mapLabel.get(objTypeName);
            if(!listObjs.contains(objTypeName)) objList.add(new SelectOption(objTypeName,objTypeLabel));
            else objList.add(new SelectOption(objTypeName,objTypeLabel, true));
        }

		return objList;   
	}
Best Answer chosen by ForceRookie
Ajay K DubediAjay K Dubedi
Hi ForceRookie,

For geting all Standard and Custom Objects use bellow code it may helpful for you.
List<string> SObjectList = new List<string>();

for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()){
   String name = objTyp.getDescribe().getName();

 if(!name.containsignorecase('history') && !name.containsignorecase('tag')&&
    !name.containsignorecase('share') && !name.containsignorecase('feed')){      
      SobjectList.add(name);
      System.debug( 'Name : ' + name);
  }

}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi

All Answers

NagendraNagendra (Salesforce Developers) 
Hi,

Sorry for this issue you are facing.

Below is a solution which will give you a list of all standard and custom objects ignoring system objects.
public List < SelectOption > getStandardCustomIgnoreSytemObjects() {
    List < SelectOption > options = new List < SelectOption > ();
    for (Schema.SObjectType item1: Schema.getGlobalDescribe().values()) {
        String name = item1.getDescribe().getName();
        // Exclude all the unwanted Sobjects e.g. CustomSettings, History, Share, Feed, ApexClass, Pages etc..
        if (!item1.getDescribe().isCustomSetting() && item1.getDescribe().getRecordTypeInfos().size() > 0 && item1.getDescribe().isCreateable() &&
            !name.containsignorecase('history') && !name.containsignorecase('tag') && !name.containsignorecase('share') && !name.containsignorecase('feed')) {
            options.add(new SelectOption(item1.getDescribe().getName(), item1.getDescribe().getLabel()));
        }
    }
    options.add(new SelectOption('Asset', 'Asset')); // Asset doesn't come-up, so explicitly add same.
    options.sort();
}
Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra
 
Deepali KulshresthaDeepali Kulshrestha
Hi ForceRookie,

To get the list of all objects in your org, you can use something like this:

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();

for(Schema.SObjectType thisObj : gd.values()) {
    System.debug(thisObj);
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
Ajay K DubediAjay K Dubedi
Hi ForceRookie,

For geting all Standard and Custom Objects use bellow code it may helpful for you.
List<string> SObjectList = new List<string>();

for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()){
   String name = objTyp.getDescribe().getName();

 if(!name.containsignorecase('history') && !name.containsignorecase('tag')&&
    !name.containsignorecase('share') && !name.containsignorecase('feed')){      
      SobjectList.add(name);
      System.debug( 'Name : ' + name);
  }

}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
This was selected as the best answer
ForceRookieForceRookie

Thank you everyone!

If you know about integration as well, please help me answer my question here -- https://developer.salesforce.com/forums/?id=9062I000000IK4lQAG