Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Salesforce Developer
easy

What are Schema describe calls and when do you use them?

Schema is the namespace for runtime metadata access in Apex. Describe calls let your code inspect objects, fields, and picklist values without hard-coding API names.

Common patterns:

`apex // Describe one object Schema.DescribeSObjectResult ad = Account.SObjectType.getDescribe(); Map<String, Schema.SObjectField> fields = ad.fields.getMap();

for (Schema.SObjectField f : fields.values()) { Schema.DescribeFieldResult df = f.getDescribe(); System.debug(df.getName() + ' (' + df.getType() + ')'); }

// Get all objects in the org Map<String, Schema.SObjectType> globalDescribe = Schema.getGlobalDescribe();

// Get picklist values List<Schema.PicklistEntry> stages = Opportunity.StageName.getDescribe().getPicklistValues(); for (Schema.PicklistEntry pe : stages) { System.debug(pe.getValue() + ' / ' + pe.getLabel()); }

// Check FLS at runtime if (Schema.sObjectType.Account.fields.Phone.isAccessible()) { ... } if (Schema.sObjectType.Account.fields.Phone.isUpdateable()) { ... } `

Use cases:

  • Generic framework code that operates on any object — no hard-coded field names.
  • Dynamic SOQL — build query strings from describe results.
  • FLS checks — verify the running user can access fields before reading/writing.
  • Picklist value validation — confirm an inbound value is a valid picklist entry.
  • Schema introspection tools — admin utilities that report on org structure.

Performance: describe calls are cached in Apex transaction. First call is slower; subsequent calls in the same transaction are essentially free. Can also use Limits.getDescribeRows() to monitor.

Test data factories that work for any object commonly use describe calls to figure out which required fields need values.

Why this answer works

Foundational dynamic Apex. Mentioning FLS checks and the cache behaviour signals depth.

Follow-ups to expect

Related dictionary terms