# Dynamic Apex: describes, dynamic SOQL and Type

*Platform Developer II Study Guide · Process Automation, Logic, and Integration · Last updated October 16, 2026 · https://www.certifyforce.com/study-guide/platform-developer-ii/process-automation-logic-and-integration/dynamic-apex-describes-dynamic-soql-and-type*

Pick the dynamic Apex feature a requirement needs: sObject tokens and describes, dynamic SOQL bind rules and Database.queryWithBinds, SOQL injection defences, dynamic DML with get, put and getSObject, Type.forName for plug-in classes, and dynamic SOSL.

- Certification: Salesforce Platform Developer II
- Exam section: Process Automation, Logic, and Integration
- Study guide: https://www.certifyforce.com/study-guide/platform-developer-ii

**Official exam objective:**

> Given a scenario and requirements, identify the appropriate dynamic Apex feature to use in the solution.

## What the exam expects

- Choose the dynamic Apex feature for a requirement whose object, field, class or filter is only known at run time.
- Get sObject tokens and describe results: from a record Id, from an object name in a variable, record type IDs by developer name, active picklist values.
- Write dynamic SOQL that compiles and runs: simple bind variables, `Database.queryWithBinds`, and injection-safe user input.
- Create and read records generically with `newSObject`, `get`, `put` and `getSObject`.
- Instantiate a class named in configuration with `Type.forName`, and read dynamic SOSL results.

Key terms: **token** (a lightweight, compile-time-validated reference to an sObject or field, such as `Account.SObjectType`), **describe result** (`DescribeSObjectResult` or `DescribeFieldResult`, the metadata behind a token), **dynamic SOQL/SOSL** (a query string built and run at run time), **dynamic DML** (creating and saving records of a type chosen at run time), **SOQL injection** (user input that changes a dynamic query's structure).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| Record Id to object | `Id.getSObjectType()` returns the token; no query | [Id Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_id.htm) |
| Object name to token | `Schema.getGlobalDescribe().get(name)`; keys are case-insensitive | [Accessing All sObjects](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_global_describe.htm) |
| New record of run-time type | `token.newSObject()` | [Dynamic DML](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_dml.htm) |
| Record type by developer name | `getRecordTypeInfosByDeveloperName()` | [DescribeSObjectResult Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_sobject_describe.htm) |
| Picklist values | `getPicklistValues()` returns active entries only | [DescribeFieldResult Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_fields_describe.htm) |
| Bind field in Database.query | Not supported: "Variable does not exist" | [Dynamic SOQL](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm) |
| Database.queryWithBinds | API 57.0+; binds from a map; access level argument | [Dynamic SOQL](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm) |
| escapeSingleQuotes | Adds `\` before each single quote in user input | [SOQL Injection](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/pages_security_tips_soql_injection.htm) |
| Parent via lookup | `getSObject('Account')`; `get()` reads fields on the record itself | [Dynamic DML](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_dml.htm) |
| Type.forName from a package | Use `forName('', name)` for a subscriber class in a no-namespace org | [Type Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_type.htm) |
| Dynamic SOSL results | One list per object, in RETURNING order | [Dynamic SOSL](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_sosl.htm) |

## Check yourself

- Why does `:filter.Priority__c` fail in `Database.query` when it works in inline SOQL?
- When should code compare tokens instead of querying to learn a record's object?
- Why must a managed package pass an empty namespace to `Type.forName` for a subscriber class?
- What does `results[0]` hold after `Search.query` with `RETURNING Account(Id), Contact(Id)`?

## Sources

- [Dynamic Apex](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic.htm)
- [Dynamic SOQL](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm)
- [Database Operations Run in User Mode by Default, Not System Mode](https://help.salesforce.com/s/articleView?id=release-notes.rn_apex_default_user_mode.htm&language=en_US&release=262&type=5)
- [Dynamic DML](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_dml.htm)
- [Understanding Apex Describe Information](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_describe_objects_understanding.htm)
- [Accessing All sObjects](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_global_describe.htm)
- [Dynamic SOSL](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_sosl.htm)
- [SOQL Injection](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/pages_security_tips_soql_injection.htm)
- [Type Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_type.htm)
- [Id Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_id.htm)
- [DescribeSObjectResult Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_sobject_describe.htm)
- [DescribeFieldResult Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_fields_describe.htm)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit and reading progress are included in the full study guide. The separate practice exams option includes the reviewed question bank and timed mock exams. The bundle includes both where available. See [current options and prices](https://www.certifyforce.com/pricing).
