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
Harshitha kaurHarshitha kaur 

how to avoid Schema describe method which was used inside for loop ?

for ex:  for(Sobject sobj : Database.Query(sobjQuery)) 
Is there any other way to represent this?
Best Answer chosen by Harshitha kaur
Manish  ChoudhariManish Choudhari
Can you please explain the question bit more with what exactly you are looking for.

You can use Schema Describe calls outside for loops or within for loops to get metadata depending on your requirement.

For Ex.:
 
for ( Schema.SObjectType type : Schema.getGlobalDescribe().values() ) {

            sObjectNames.add(new SelectOption(String.valueOf(type), String.valueOf(type)));//Fetch object name and add in selectoption list

        }

OR 
 
List<Schema.SObjectType> sObjects = Schema.getGlobalDescribe().values();

Both of above scenarios will work.

Check out this post for dynamic apex: http://sfdcfacts.com/apex/dynamic-record-display-how-to-display-record-of-any-sobject-on-same-visualforce-page/

Let me know if this helps.

**Please mark this as best answer if this answers your query.**

Thanks,
Manish Choudhari
14x Certified Salesforce Architect
Certification link:
 http://certification.salesforce.com/certification-detail-print?conId=003G000002gRrrEIAS 
My Blog: http://sfdcfacts.com/
Youtube Channel: https://www.youtube.com/SFDCFacts
LinkedIn: https://www.linkedin.com/in/manish-choudhary/
Trailhead: https://trailhead.salesforce.com/en/me/manish-choudhari
Twitter: https://mobile.twitter.com/manish_sfdc