by Geoff Escandon (@gjescandon)
“What’s in a name? That which we call a rose
By any other name would smell as sweet.”
– Romeo and Juliet
As we delve into custom Apex using
controllers, or perhaps even
RESTful services, we need to know the API names of the objects that we are working with. The
Force.com documentation has many examples using Accounts or Contacts and life is easy with those objects. We also know from the UI that custom objects and fields are assigned API names in a consistent manner, with underscores in between words and suffix of ‘__c’. For example, my custom object, named ‘My Custom Object’, has an API name of ‘My_Custom_Object__c’.Sooner or later, though, we want to work with Opportunity Products. How will you know that the API name for the Opportunity Product object is actually
OpportunityLineItem? What does it take to figure out that the API names for Product and Pricebook are
Product2 and
Pricebook2, respectively?The Force.com
Object Reference doc is your one-stop shopping for all object and field descriptions available in the Force.com API. In addition to exceptions like OpportunityLineItem, the Object Reference also has Data Model diagrams which relate the standard objects to one another.
Another way to access the Object Reference is through the Force.com Utility Belt, which is a Chrome extension built by Jeff Douglas. This chrome extension actually puts several of the Force.com reference documents at your Chrome finger tips. Of course you know, Batman also uses a utility belt. Just sayin.
So now we know the API name for Opportunity Product is one of a few exceptions in the otherwise consistent Force.com API. As you go deeper into the Force.com platform, you will certainly run into other exceptions to convention. Be sure to keep one of these reference tools nearby to help you when you hit it!