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


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

Both of above scenarios will work.

Check out this post for dynamic apex:

Let me know if this helps.

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

Manish Choudhari
14x Certified Salesforce Architect
Certification link: 
My Blog:
Youtube Channel: