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
VenkataRajaVenkataRaja 

SOQL on all custom objects

Hi,

public class CustomObjectsInPickListCntrl
{
public String val {get;set;}
      public void getName()
     {
         List<SCHEMA.SOBJECTTYPE> gd = Schema.getGlobalDescribe().Values();     
         List<String> customObjectList = new List<String>();
       
       for(Schema.SObjectType f : gd)
       {
                  
         
          Schema.DescribeSObjectResult res = f.getDescribe();
          if(res.isCustom())
          {
              if(!res.isCustomSetting())
              {                 
                  customObjectList.add(f.getDescribe().getName());
              }
          }
       }
          
     }
}

In the above code customObjectList has all custom objects

I have to get like this

for(SObject s : customObjectList){
     List<s> slist =  [Select Id LastModifiedDate from s];
}

If I wirte like this I will get SOQL Exception (100), so How I can do now. Please advice any one.
Elie.RodrigueElie.Rodrigue
You would need to use a batch job:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm 
Vinita_SFDCVinita_SFDC
Hello,

Please move query out of "for loop". Refer section "Using Collections, Streamlining Queries, and Efficient For Loops" in following help document:


http://wiki.developerforce.com/page/Apex_Code_Best_Practices

VenkataRajaVenkataRaja
Hi Vinita and Elie,

Thanks for reply, Can you please send sample code on batch apex to query single latest record(based on LastModifiedDate) from each object without getting SOQL exception?
Note: I have to query on all custom objects in my sandbox(~500).