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
PeacePeace 

Fetch few standard objects

Hi,

 

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

Rahul_sgRahul_sg
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.
http://www.salesforce.com/us/developer/docs/soql_sosl/index.htm
PeacePeace

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:

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_list.htm

 

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'))  ) 
        {
            stdObjectNames.add(sobjName);
            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()));
}
}

 

 

 

 

Rahul_sgRahul_sg
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.
PeacePeace

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