Intermediate 30 min read

Schema Describe Basics

By the end of this lesson, you'll be able to:

  • Use Schema methods to inspect an object or field's metadata at runtime
  • Check whether a field is accessible or updateable before using it
  • Explain why describe calls are useful for building genuinely reusable Apex

Prerequisites: "Dynamic sObjects"

Describing an object

Schema.DescribeSObjectResult accountDescribe = Account.sObjectType.getDescribe();

System.debug(accountDescribe.getLabel());       // "Account"
System.debug(accountDescribe.isCreateable());   // true or false, depending on permissions

getDescribe() returns metadata about the Account object itself — not a specific record, but facts about the object type: its label, and whether the current running context is even allowed to create one.

Describing a field

Schema.DescribeFieldResult industryField =
    Account.Industry.getDescribe();

System.debug(industryField.getLabel());      // "Industry"
System.debug(industryField.getType());       // PICKLIST
System.debug(industryField.isAccessible());  // true or false

The same idea applies at the field level — this is metadata about the Industry field (its label, its data type, whether it's currently readable), independent of any particular Account record's actual Industry value.

Why this matters: checking access before using a field

if (Account.Industry.getDescribe().isUpdateable()) {
    acc.Industry = 'Retail';
    update acc;
} else {
    System.debug('Current user cannot update the Industry field.');
}

Rather than assuming every user running this code has permission to update Industry, checking isUpdateable() first lets the code react gracefully instead of failing with a permissions error partway through — genuinely reusable code that adapts to who's actually running it, a concept a later Security module builds on significantly.

Exercise

Write code that describes the Contact object and debugs its label using getLabel().

Show hint

Contact.sObjectType.getDescribe().getLabel()

APEX

Schema Describe Basics Quiz

1. What does a Schema describe call provide?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

Schema describe calls let Apex inspect an object or field's own metadata at runtime — its label, its type, whether the current user can even see it — rather than assuming.