3

The CustomObject table that can be accessed via the Tooling API includes fields like:

  • NamespacePrefix
  • DeveloperName

that provide enough information for a Custom Object API name to be constructed as e.g. myns__MyName__c.

Platform Events (that also appear in this table) require a __e suffix not a __c suffix, but I don't see any field that signals that apart from the fragile convention that the the DeveloperName ends in Event.

Am I missing something here?

(I have some permission set filtering logic driven by CustomObject and CustomField and this problem is making the code ugly.)

2
  • 1
    So... I'm going out on a limb here, but I think this is an X-Y Problem. My reasoning is that you're trying to determine something you can't possibly determine from the API you've chosen as your source of data. What is the actual problem you're trying to solve? What's the context (e.g. Apex, a web app, etc)? – sfdcfox Mar 14 at 5:45
  • FYI @sfdcfox: The context is Apex where I am filtering out objects and fields from permission sets contained in one managed package (A) to match the objects and fields present in some depended on managed packages (X, Y, Z). The behaviour of A degrades with earlier versions of X, Y, Z but A still needs to be installable. The permission sets are held in A as static resources and filtered as in the question here via a Setup page. There are many version permutations of X, Y, Z. – Keith C Mar 14 at 20:12
3

I'm not sure you can distinguish Platform Events from other custom objects solely with queries against the Tooling API CustomObject.

What you could to is take the DurableId's for the records of interest and query for them against EntityDefinition.

As you say, you could then identify the Platform Events by their __e suffix or that they KeyPrefix for their records will start with an e (e00, e01, ...).

select DurableId, QualifiedApiName, NamespacePrefix, DeveloperName, KeyPrefix 
from EntityDefinition 
where DurableId in ('01I0g000000Qe7F', '01I0g000000Qebo')

Alternatively, you do use one query to identify the DurableId's for the Platform Events defined in the org:

select DurableId, QualifiedApiName, NamespacePrefix, DeveloperName, KeyPrefix 
from EntityDefinition
where KeyPrefix like 'e%'
1
  • 1
    Wasn't aware of EntityDefinition at all. Thanks! – Keith C Mar 15 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.