Skip to content

Salesforce Prep

Expert Tips for Interviews & Certifications

  • Home
  • Current Page Parent Start Learning
  • About Me
  • Privacy Policy
  • Home
  • Current Page Parent Start Learning
  • About Me
  • Privacy Policy

LIST OF CONTENT

    • Order of Execution, Transactions, Savepoints, Partial Success & Locking in Salesforce
    • Record Types, Page Layouts, Dynamic Forms, and Picklist Strategy
    • Relationship Design: Master-Detail vs. Lookup, Junctions, and Roll-Ups
    • Mastering Salesforce Data Types: Objects, Fields, External Objects, Big Objects & Polymorphic Fields
    • Multi-Tenancy, Governor (Trust) Limits, Hyperforce & Data Residency in Salesforce
    • See all Platform & Data Model posts
    • Exception Handling & Error Management in Apex
    • Advanced OOP Concepts in Apex
    • Object-Oriented Programming in Apex
    • Collections & Data Structures in Apex
    • Control Flow & Logic in Apex
    • Apex Language Fundamentals
    • Salesforce Architecture, Org Types & Metadata
    • Apex Syntax Basics
    • Secure Coding in Salesforce: SOQL Injection, XSS/CSRF, and Secrets Hygiene
    • Callouts in Apex: Secure Auth, Non-Blocking UX, and Resilient Retries
    • Error Strategy in Salesforce Apex: Custom Exceptions, Fail-Fast Validation, Correlation IDs & Telemetry
    • Apex Security Essentials — with/without sharing and CRUD/FLS with Security.stripInaccessible
    • Service / Repository / Unit of Work in Apex — Keeping the Domain Layer Clean
    • See all Basic Apex & Programming posts
    • Packaging & Managed Packages in Salesforce
    • Apex Design Patterns
    • Logging, Debugging & Monitoring in Apex
    • Caching & Performance Enhancements in Apex
    • Custom Metadata & Configuration
    • Dynamic Apex & Metadata Access
    • Apex with Flow & Automation
    • Event-Driven Architecture in Salesforce
    • REST Services & Serialization in Apex
    • Integrations & Callouts in Apex
    • Asynchronous Apex
    • Testing Advanced Scenarios in Apex
    • Testing Apex Code
    • Security & Sharing in Apex
    • Governor Limits & Performance Tuning
    • Trigger Frameworks & Best Practices
    • Triggers Fundamentals
    • External Event Consumption in Salesforce — Retries & Dead-Letter Concepts
    • Pub/Sub API vs Streaming API (CometD/EMP): Ordering & At-Least-Once Delivery in Salesforce
    • Platform Events vs Change Data Capture — Use Cases & Trade-offs (Salesforce)
    • Event Schema Versioning, Correlation IDs, Idempotency & Deduplication in Salesforce
    • See all Advanced Apex posts
    • DML Operations & Transactions in Apex
    • Advanced SOQL & SOSL
    • SOQL Fundamentals
    • Salesforce Flow – Overview & Key Concepts
    • Platform Events with Idempotent Consumers and Durable Replay Options (Salesforce)
    • Handling Large Data Volumes in Salesforce: Smart Batch Design, QueryMore, and Governor Limit Strategies
    • Chaining Strategies, State Management, Error Handling & Monitoring in Salesforce Apex
    • Future vs Queueable vs Batch vs Schedulable in Salesforce Apex: A Practical Selection Guide
    • Transactional Integrity in Apex: Mastering Partial Success, Savepoints, and Rollbacks
    • Trigger Timing, Cross-Object Updates, and Asynchronous Escalation in Salesforce Apex
    • Bulkification, Mixed DML, and Lock Avoidance in Salesforce Apex
    • One Trigger per Object, Handler Pattern, and Recursion Guards in Salesforce Apex
    • Platform Cache Patterns in Salesforce — Safe Caching & Invalidation
    • SOSL vs SOQL, Search Tuning, and Skinny Tables
    • Relationship & Aggregate SOQL, Subqueries, and Avoiding N+1 in Salesforce
    • Salesforce SOQL/SOSL Selectivity & Query Plan — Standard, Custom & Compound Indexes
    • See all Automation Process posts
    • Middleware Patterns (MuleSoft / Kafka / AWS / Azure) & Error Routing — A Practical Integration Guide
    • Salesforce Integration Simplified: Webhooks, Platform Events & Callouts
    • OAuth 2.0: Choosing the Right Flow for Your App
    • API Contracts You Can Trust: Versioning, Pagination, Error Model, Idempotency Keys
    • Salesforce API Guide: REST, SOAP, Bulk, Composite, and GraphQL Explained
    • See all APIs & Integrations posts
    • Packaging & Managed Packages in Salesforce
    • Deployment & DevOps in Salesforce
    • Advanced Apex & Edge Cases
    • Dependency Injection & Clean Architecture in Apex
    • See all Security & Delivery posts
    • No posts yet
    • See all LWC posts
    • No posts yet
    • See all VISUAL FORCE posts
    • Interview, Certification & Project Readiness
    • Real-World Apex Best Practices
    • See all Pro & Career posts
    • No posts yet
    • See all Sub Category posts

Home » Dynamic Apex & Metadata Access

Advanced Apex

Dynamic Apex & Metadata Access

Share

What Is Dynamic Apex?

Short Description

Dynamic Apex lets your code adapt at runtime based on object names, field names, or metadata—without hardcoding them.

Simple Explanation

Dynamic Apex is like a universal remote—one controller that works for many devices.


Gist (Quick Revision)

Dynamic Apex makes code flexible and reusable by reading metadata at runtime.


1. Schema Describe (Metadata Access)

What Is Schema Describe?

Schema Describe allows Apex to read Salesforce metadata such as:

  • Objects

  • Fields

  • Data types

  • Permissions (CRUD/FLS)

Real-Life Example

A form that shows fields based on configuration, not hardcoded rules.


Basic Schema Describe Example

Schema.DescribeSObjectResult d =
    Account.SObjectType.getDescribe();

System.debug(d.getName());
System.debug(d.isCreateable());

Describe Fields Dynamically

Map<String, Schema.SObjectField> fields =
    Account.SObjectType.getDescribe().fields.getMap();

for (String fieldName : fields.keySet()) {
    System.debug(fieldName);
}

Why Schema Describe Matters

  • Build generic utilities

  • Enforce security dynamically

  • Reduce code duplication


Gist (Quick Revision)

Schema Describe lets Apex understand Salesforce structure at runtime.


2. Type Class & Reflection

What Is the Type Class?

The Type class enables reflection—creating and working with classes dynamically by name.

Simple Explanation

Reflection lets Apex discover and create objects at runtime.


Real-Life Example

A plugin system where logic is chosen based on configuration.


Type Class Example

Type t = Type.forName('MyService');
Object obj = t.newInstance();

Calling Methods Dynamically (Conceptual)

((MyService)obj).execute();

When to Use Reflection

  • Frameworks

  • Plugin-style architectures

  • Highly configurable systems


Gist (Quick Revision)

The Type class allows dynamic class loading and execution.


3. Dynamic Apex Use Cases

Use Case 1: Generic Trigger or Service

One handler works for many objects using metadata.


Use Case 2: Security Enforcement

Check CRUD/FLS dynamically:

if (Schema.sObjectType.Account.isUpdateable()) {
    update acc;
}

Use Case 3: Config-Driven Logic

Control behavior using:

  • Custom Metadata

  • Custom Settings

Change behavior without changing code.


Use Case 4: Generic Data Processing

Process records based on object name:

String objName = 'Account';
SObject sobj = Schema.getGlobalDescribe().get(objName).newSObject();

Risks & Best Practices

⚠️ Overuse can:

  • Reduce readability

  • Make debugging harder

✅ Best practice:

  • Use Dynamic Apex only when needed

  • Keep logic documented and tested


Gist (Quick Revision)

Dynamic Apex is powerful—use it for flexibility, not everywhere.

  • January 6, 2026

Tags: Dynamic ApexSchema describe ApexSalesforce metadata accessApex Type classApex reflectionDynamic Apex use casesAdvanced Apex programming

Share on Facebook
Share on X
  • Next Custom Metadata & Configuration
  • Previous Apex with Flow & Automation

You may also like...

  • api contracts versioning pagination error model idempotency keys featured image.jpg

    API Contracts You Can Trust: Versioning, Pagination, Error Model, Idempotency Keys

  • salesforce event schema versioning correlation idempotency featured image.jpg

    Event Schema Versioning, Correlation IDs, Idempotency & Deduplication in Salesforce

  • Apex Language Fundamentals

    Apex Language Fundamentals

  • salesforce data types external big polymorphic

    Mastering Salesforce Data Types: Objects, Fields, External Objects, Big Objects & Polymorphic Fields

  • Exception Handling & Error Management in Apex

    Exception Handling & Error Management in Apex

  • salesforce apex error handling fail fast custom exceptions correlation telemetry feature image.jpg

    Error Strategy in Salesforce Apex: Custom Exceptions, Fail-Fast Validation, Correlation IDs & Telemetry

  • Apex with Flow & Automation

    Apex with Flow & Automation

  • salesforce platform cache patterns safe caching invalidation hero

    Platform Cache Patterns in Salesforce — Safe Caching & Invalidation

  • Custom Metadata & Configuration

    Custom Metadata & Configuration

  • Dependency Injection & Clean Architecture in Apex

    Dependency Injection & Clean Architecture in Apex

  • Salesforce Integration Simplified: Webhooks, Platform Events & Callouts

    Salesforce Integration Simplified: Webhooks, Platform Events & Callouts

  • Salesforce Flow – Overview & Key Concepts

    Salesforce Flow – Overview & Key Concepts

  • Apex Design Patterns

    Apex Design Patterns

  • salesforce batch apex large data processing feature image.jpg

    Handling Large Data Volumes in Salesforce: Smart Batch Design, QueryMore, and Governor Limit Strategies

  • salesforce platform events vs change data capture featured image.jpg

    Platform Events vs Change Data Capture — Use Cases & Trade-offs (Salesforce)

Categories

Recent Posts

  • Interview, Certification & Project Readiness January 6, 2026
  • Real-World Apex Best Practices January 6, 2026
  • Packaging & Managed Packages in Salesforce January 6, 2026
  • Deployment & DevOps in Salesforce January 6, 2026
  • Advanced Apex & Edge Cases January 6, 2026
  • Dependency Injection & Clean Architecture in Apex January 6, 2026
  • Apex Design Patterns January 6, 2026
  • Logging, Debugging & Monitoring in Apex January 6, 2026
  • Caching & Performance Enhancements in Apex January 6, 2026
  • Custom Metadata & Configuration January 6, 2026

Tags

Selective Queries Selective SOQL Semi-Join Separation of Concerns Serverless Patterns Session cache sharing-and-security Shield Encryption Skinny Tables SNS Fanout Soft TTL SOQL soql-injection SOQL best practices SOQL Injection Prevention SOQL vs SOSL SOSL SQS DLQ Standard Objects Step Functions Streaming API Streaming API CometD stripinaccessible Testability Token Refresh Transactional Integrity Transaction Management Trigger Handler Pattern Triggers Trigger Timing Trust Limits Type-ahead search TYPEOF UI API Unit of Work UX Versioned keys versioning web security WhatId WhoId Without Sharing with sharing WITH SNIPPETS xss-csrf

RECENT POSTS

  • Interview, Certification & Project Readiness
  • Real-World Apex Best Practices
  • Packaging & Managed Packages in Salesforce
  • Deployment & DevOps in Salesforce
  • Advanced Apex & Edge Cases

SEARCH

Salesforce Prep © 2026. All Rights Reserved.