ApexTypeImplementor
Represents Apex classes that directly or indirectly implement an interface. Using a SOQL query, this object gets information about public or global classes and only global classes for installed managed packages.
Introduced in API version 54.0.
describeSObjects(), query()
-
Type: reference
-
Properties: Filter, Group, Sort
-
Description:
The foreign key to the outer class that contains the Apex class implementing the interface.
This is a relationship field.
-
Relationship name: ApexClass
-
Relationship type: relationship
-
Refers to: ApexClass
- Type: string
- Properties: Filter, Group, Sort
- Description: Apex class name that implements the interface. For an inner class that implements the interface, the outer class and inner name separated by a period.
- Type: string
- Properties: Filter, Group, Nillable, Sort
- Description: The namespace prefix of the class that implements the interface.
- Type: string
- Properties: Filter, Group, Nillable, Sort
- Description: A unique identifier for the interface and implementor.
-
Type: reference
-
Properties: Filter, Group, Nillable, Sort
-
Description:
The foreign key to the outer class that contains the Apex class defining the interface. Null for built-in system interfaces, such as
System.Batchable.This is a relationship field.
-
Relationship name: InterfaceApexClass
-
Relationship type: relationship
-
Refers to: ApexClass
- Type: string
- Properties: Filter, Group, Sort
- Description: The interface name for which Apex class implementation is retrieved. For an inner interface, the outer Apex class name and the inner interface name separated by a period.
- Type: string
- Properties: Filter, Group, Nillable, Sort
- Description: The namespace prefix of the class that defines the interface.
- Type: boolean
- Properties: Defaulted on create, Filter, Group, Sort
- Description: Indicates whether the implementing class is abstract (
false) or not (true).
ApexTypeImplementor considers access modifiers based on the context, such as the namespace from which the ApexTypeImplementor entity is queried. These are additional usage considerations.
- In installed managed packages, you get information about all global implementors in the org, and public implementors from the managed package itself.
- ApexTypeImplementor appropriately filters classes that are annotated with
@Deprecated. For example it respects the package version dependency settings of a class when queried from that class. - ApexTypeImplementor returns implementors where
ApexClass.IsValidis set toFalse(invalid classes) in addition to when it’s set toTrue. Classes that don’t compile or execute can be returned. An implementor class is only guaranteed to be usable ifApexClass.IsValidis set toTruefor the implementor. - If a package is installed but not yet compiled because Compile on Deploy is disabled, ApexTypeImplementor returns no values until compilation is complete. In environments like sandboxes where Compile on Deploy can be disabled, you must perform a manual compilation to get complete results.
- To avoid cross-namespace collisions, always specify an InterfaceNamespacePrefix as a WHERE clause in SOQL queries for ApexTypeImplementor. Otherwise, the query includes all namespaces instead of only the current namespace. If a package contains an interface with the same name as an interface in a different namespace, a query without a specified InterfaceNamespacePrefix can return false implementors that can’t be assigned to the interface.
For example, say a managed package contains a global interface named
RoundingStrategyand a global class namedHalfDownthat implementsRoundingStrategy. If a subscriber org has an interface that’s also namedRoundingStrategy, then the query[SELECT ApexClass.Id FROM ApexTypeImplementor WHERE InterfaceName = 'RoundingStrategy'], if performed in the subscriber org, can return the ID ofHalfDowninstead of an implementor in the subscriber org. To avoid this issue, perform a query that specifies a InterfaceNamespacePrefix:[SELECT ApexClass.Id FROM ApexTypeImplementor WHERE InterfaceName = 'RoundingStrategy' AND InterfaceNamespacePrefix = 'PackageNamespace'].
This example demonstrates how an interface allows flexibility in a configuration, record, or user-driven selection of the rounding strategy to apply. The multiple implementations of the interface can be discovered using ApexTypeImplementor and the specific implementation chosen based on user requirements.