One of the many things I love about this email list is sharing my knowledge with you. But it’s not always a one-way street. Some days I learn from you.
In regards to yesterday’s email, a long-time reader mentioned there’s a more abstract way of knowing an object’s prefix. This is important because prefixes can change between sandboxes and production.
It seems there is a not well known object called Entity Definition (ED) that stores every object’s prefix. In addition to prefixes (which is stored in the field KeyPrefix), it also stores the developer name, label, and plural label.
So by adding a get operation for the ED, and using the developer name (because that never changes), you can safely find and use any object’s prefix.
This is similar to the Record Type object, which allows you to find the record type id for any object.
Combined, these objects keep things working across all your Salesforce environments.
The takeaway
Use the objects Entity Definition and Record Type to your advantage.