Skip to main content
2 commentaires
  1. 7 août 2025, 11:31

    Tooling API vs Metadata API (Simple Explanation) 

     

    Tooling API 

    • Designed for developer tools (VSCode, Developer Console, etc.)
    • Can access runtime information (e.g., ApexClass, LightningComponentBundle)
    • Faster and easier for use in Apex
    • Commonly used to query: Apex classes, LWC, Triggers, etc.

     

    Metadata API

    • Used for deployment and configuration.
    • Accesses complete metadata (e.g., Object schema, Layouts, Flows)
    • Needs Session ID with OAuth, not always available inside Flows or Agents.
    • Cannot be queried easily using Apex in real-time – usually used via external tools or HTTP callouts.

     

    Why You’re Getting Zero in Flow/Agent 

     

    • When using Metadata API in Apex, it usually requires callouts with valid Session ID.
    • In Flow/Agent, that Session ID is often null or restricted due to platform security.
    • Tooling API inside Apex may not return results when invoked from Flow or Bot Agent due to permission scoping.
    • Anonymous Apex (Dev Console) runs with full user-level permissions, which is why it works there.

     

    Recommended: Use Tooling API with Apex (Simple Count Logic) 

     

    Here’s working Apex code to count: 

     

    • Lightning Web Components
    • Flows
    • Process Builders
    • Custom Objects (Excluding Managed Packages)
     public class OrgMetadataCounter {    public class MetadataCountResult {        public Integer lwcCount;        public Integer flowCount;        public Integer pbCount;        public Integer customObjectCount;    }    public static MetadataCountResult getComponentCounts() {        MetadataCountResult result = new MetadataCountResult();        // LWC Count (Tooling API)        result.lwcCount = [SELECT COUNT() FROM LightningComponentBundle WHERE NamespacePrefix = null AND DeveloperName != null];        // Flow Count (Metadata API via Tooling)        result.flowCount = [SELECT COUNT() FROM FlowDefinitionView WHERE ProcessType = 'Flow'];        // Process Builder Count        result.pbCount = [SELECT COUNT() FROM FlowDefinitionView WHERE ProcessType = 'Workflow'];        // Custom Object Count (Standard + Custom, Excluding Managed Packages)        result.customObjectCount = [SELECT COUNT() FROM CustomObject WHERE NamespacePrefix = null];        return result;    }}
0/9000