Sub topic 2
Standard objects: Account, Contact, Lead, Opportunity, Case and more
This chapter assumes you know how to navigate Setup, understand tables, rows and foreign keys, and have read the previous chapter on objects, fields and records. Here you will learn what standard objects are, what the core ones do, and how they connect.
What makes an object standard
A standard object is an object that Salesforce includes in every org. You don't create it, and you can't delete it. You can add custom fields, change page layouts, and control access to it. Salesforce defines its built-in fields, such as Name and Industry on Account.
Standard objects carry built-in behavior. Examples are lead conversion, opportunity stages and forecasting, and case escalation. A custom object you build yourself has none of this behavior unless you create it.
Standard API names have no suffix. The object is Account, not Account__c. Custom fields you add to a standard object do get the __c suffix, for example Account.Region__c.
The core sales and service objects
| Object | Represents | Typical use |
|---|---|---|
| Account | A company or organization (or a person, if Person Accounts are enabled) | The customer or partner that other records hang off |
| Contact | An individual associated with an account | People you talk to at a customer |
| Lead | An unqualified prospect not yet tied to an account | Early-stage marketing and sales prospecting |
| Opportunity | A potential sale with an amount, stage and close date | Pipeline tracking and forecasting |
| Case | A customer issue or question | Support and service |
Other widely used standard objects include Campaign, Contract, Order, Product2, Pricebook2, Task, Event, User and Report. Which ones you see depends on your edition and which features are enabled.
How the core objects connect
The standard objects are linked by relationship fields. A Contact has an AccountId field that points to its Account. An Opportunity also has an AccountId. A Case can point to both an Account and a Contact.
Account sits at the center. Most other records point to it, which is why Account is usually the first object you think about when you design a data model.
Lead conversion
A Lead stands alone. When a sales rep qualifies it, the rep converts it. Conversion creates an Account and a Contact, and optionally an Opportunity, from the lead's data. The original Lead record is kept and marked as converted. It is no longer editable and no longer appears in normal lead views.
This is the main behavior that makes Lead different from Contact. If you model prospects with a custom object instead, you must rebuild this conversion process yourself.
Reading standard objects in SOQL
SOQL queries use the API names. This query reads Account and uses the child relationship name Contacts to return each account's related contacts:
SELECT Id, Name, Industry,
(SELECT FirstName, LastName FROM Contacts)
FROM Account
WHERE Industry = 'Technology'
LIMIT 10The inner query is a subquery on the child relationship. Standard relationship names are plural, such as Contacts, Opportunities and Cases.
Checking whether an object is standard
You can ask Apex whether an object is custom. The describe methods return a DescribeSObjectResult, and its isCustom() method returns false for standard objects.
Schema.DescribeSObjectResult accountDescribe = Account.SObjectType.getDescribe();
Schema.DescribeSObjectResult invoiceDescribe = Invoice__c.SObjectType.getDescribe();
System.debug(accountDescribe.getName() + ' custom? ' + accountDescribe.isCustom());
System.debug(invoiceDescribe.getName() + ' custom? ' + invoiceDescribe.isCustom());This example assumes your org has a custom object named Invoice__c. It prints false for Account and true for Invoice__c.
Common errors
- Querying a field that doesn't exist or isn't visible. The query fails with "No such column". The field may be misspelled, or the running user may lack field-level access. Security is covered in a later chapter.
- Using the wrong child relationship name.
FROM Contactworks in a subquery only asFROM Contacts. Check the relationship name on the lookup field, not the object name. - Expecting Lead and Contact to behave alike. Leads have no account lookup until they are converted.
- Assuming every org has every object. Objects such as
OrderorContractdepend on enabled features.
Exercise
A sales rep converts a Lead and chooses to create an Opportunity. Which records exist afterward, and what happens to the original Lead?
Show answer
An Account, a Contact and an Opportunity are created from the lead's data. The Lead record is kept but marked as converted, and it can no longer be edited.
Exercise
You add a field called Region to the standard Account object. What is its API name, and how does it differ from the API name of Account itself?
Show answer
The field's API name is Region_c, because custom fields end in the _c suffix. The standard object Account has no suffix.