+ Start a Discussion

Fetch few standard objects



I am new to Salesforce. I have a doubt..


Can we fetch only those standard objects which are usually displayed as tabs on home page such as Campaigns, Leads, Contacts, Accounts, Opportunities, Forecasts, etc.  Without hardcoding names of the object in Code.

Is it possible?


Please help

No as a system admin you can access most of the standard objects using their name in SOQL. For few std objects you need extra privileges e.g. marketing user checkbox, CRM content user checkbox at the user profile level.

Thanks for ur reply..


So if i want to fetch only those standard objects which are present under Customize tab (Name -> Setup -> Customize)

ie. excluding all the objects mentioned in the last NOTE in the following link:



Is it possible to fetch such objects (objects under customize tab) by modifying below code ?

Below code returns all standard objects.


for ( Schema.SObjectType typ : Schema.getGlobalDescribe().values() ) 
        String sobjName = String.valueOf(typ);
        if ( (!sobjName.contains('__c'))  ) 
            TestList1.add(new SelectOption(sobjName,sobjName));


OR,  following are the only two solutions ??

1. Using object names on SOQL

2. Harcoding object names in code as below:


 Set<String> stdObjectSet = new Set<String>{'Account','Contact','Lead'};  // Names of objects under Customize tab

for ( Schema.SObjectType f : Schema.getGlobalDescribe().values()){
if ( stdObjectSet.contains(f.getDescribe().getName()) ){
options1.add(new SelectOption(f.getDescribe().getName(),f.getDescribe().getLabel()));





I think we cannot use if ( (!sobjName.contains('__c')) ) as it will return all the objects.
So the options you mentioned are correct.
However, instead of hardcoding the values in code. you may want to define a custom setting a store the object names there and then use it in your code.

thanks Rahul,


Can u please explain with an example.

ie. How to implement a custom setting to store the object names and  how to use it in my code.


Please help