Sub topic 2
Standard objects: Account, Contact, Lead, Opportunity, Case and more
This chapter assumes you can navigate Setup, understand tables, rows and foreign keys, and have seen a basic SOQL query. It covers the objects that every Salesforce org ships with, what each one models, how they connect, and what you can and can't change about them.
What makes an object "standard"
A standard object is an object that Salesforce defines and maintains. It exists in every org from the start. Its API name has no suffix: Account, Contact, Opportunity. A custom object, by contrast, has an API name ending in __c.
Standard objects differ from custom ones in a few practical ways:
- You cannot delete them, and you cannot rename their API names.
- You can usually change their labels. A team that sells to schools can relabel Account as "Institution", and the API name stays
Account. - You can add custom fields, validation rules, triggers, flows, record types and page layouts to most of them.
- Some of their fields are required or have built-in behavior that you can't remove. For example,
Opportunity.StageNameandOpportunity.CloseDateare always required. - Many standard features work only with them: forecasting, lead conversion, Case escalation, Campaign influence, and Einstein features, for example.
The last point is the main reason to start with a standard object when one fits. That decision is covered in a later chapter.
The core sales and service objects
The table lists the objects you will meet most often.
| Object (API name) | What a record represents | Notable built-in behavior |
|---|---|---|
| Account | A company, organization or household you do business with | Parent of many other records. Supports account hierarchies through `ParentId`. |
| Contact | A person associated with an account | `AccountId` is optional. A contact without an account is a private contact. |
| Lead | A person or company you have not yet qualified | Can be converted into an Account, Contact and Opportunity. |
| Opportunity | A potential sale | Has a stage, close date and amount. Drives pipeline reports and forecasts. |
| Case | A customer issue or request | Has status, priority and origin. Supports queues, assignment rules and escalation. |
| Campaign | A marketing initiative | Links to leads and contacts through `CampaignMember`. |
| Product2, Pricebook2, PricebookEntry | What you sell and at what price | Opportunity products are stored in `OpportunityLineItem`. |
| Task, Event | To-dos and calendar entries (activities) | Relate to other records through `WhoId` and `WhatId`. |
| User | A person who logs in | Used for ownership, sharing and permission assignment. |
Other standard objects include Contract, Order, Asset, Quote and Solution. Which ones are available depends on your edition and which features are enabled.
Account and Contact
Account is the center of the sales and service data model. Most other objects point to it with a lookup field named AccountId.
Contact is a person. A contact normally belongs to one account through Contact.AccountId. If your org enables Contacts to Multiple Accounts, the AccountContactRelation object lets one contact be related to several accounts. The contact keeps one primary account, and the other links are stored as junction records.
Person Accounts
Some businesses sell to individuals, and a company-and-employee model doesn't fit. Person Accounts merge Account and Contact into one record for such customers. A person account is an Account record that also carries Contact-style fields, and it uses a special person account record type.
Two things to know before turning this on:
- Once enabled, Person Accounts cannot be turned off.
- Code and reports must handle both business accounts and person accounts. Field names change, for example
PersonEmailinstead ofEmail.
Lead and lead conversion
A Lead holds a prospect before you know whether there is a real deal. A lead has its own fields, including Company, Status, LeadSource and Rating. LastName and Company are required on a standard lead.
Converting a lead is a one-time operation. It creates or matches an Account and a Contact, and optionally creates an Opportunity. The lead is then marked IsConverted = true. Converted leads stay in the database, but you can't edit them in the normal way.
You can also convert leads in code. The example below creates a lead, then converts it with Database.convertLead. It looks up a status value that your org treats as converted, because the name of that status can differ between orgs.
Lead ld = new Lead(
FirstName = 'Ada',
LastName = 'Lovelace',
Company = 'Analytical Engines Ltd'
);
insert ld;
LeadStatus convertedStatus = [
SELECT MasterLabel
FROM LeadStatus
WHERE IsConverted = true
LIMIT 1
];
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(ld.Id);
lc.setConvertedStatus(convertedStatus.MasterLabel);
Database.LeadConvertResult result = Database.convertLead(lc);
System.debug('Success: ' + result.isSuccess());
System.debug('Account: ' + result.getAccountId());
System.debug('Contact: ' + result.getContactId());
System.debug('Opportunity: ' + result.getOpportunityId());Some teams skip leads and create contacts directly, which is fine. Leads are useful when you have a lot of unqualified records and don't want them cluttering accounts.
Opportunity
An Opportunity models a potential sale. Its most important fields are:
Name,StageNameandCloseDate, which are required.Amount, which is either entered directly or calculated from products.Probability, which usually follows the stage.AccountId, which links to the customer.
Stages come from a picklist that you can edit. Each stage value maps to an internal category, such as open, closed won or closed lost. Those categories drive the IsClosed and IsWon fields.
Opportunities connect to other objects in three ways:
- A lookup to Account through
AccountId. - Products through
OpportunityLineItem, which links the opportunity to aPricebookEntry. - People through
OpportunityContactRole, a junction object that links an opportunity to many contacts, each with a role such as Decision Maker.
A query that sums pipeline by stage is typical reporting work:
SELECT StageName, COUNT(Id) deals, SUM(Amount) total
FROM Opportunity
WHERE IsClosed = false
GROUP BY StageNameCase
A Case records a customer's issue. Its common fields are Subject, Status, Priority, Origin (phone, email, web) and Reason. Cases point to an AccountId and a ContactId, and both are optional.
Case has features that most standard objects lack:
- Assignment rules can route new cases to users or queues.
- Escalation rules act on cases that stay open too long.
- Email-to-Case and Web-to-Case create records from inbound messages and web forms.
- Case comments and the case feed track the conversation.
How the objects connect
The relationships among the core objects look like this:
In SOQL, you follow these links in two directions. A child-to-parent query uses dot notation on the relationship name, for example Account.Name from a contact. A parent-to-child query uses a subquery on the plural child relationship name. For standard relationships the names are plural words without a suffix, such as Contacts, Opportunities and Cases.
SELECT Id, Name, Industry,
(SELECT FirstName, LastName FROM Contacts)
FROM Account
WHERE Industry = 'Technology'
LIMIT 10For custom relationships these names get a __r suffix. The API names chapter covers that.
Activities: Task and Event
Task and Event are standard objects that attach to almost anything. Each has two polymorphic lookup fields, which means the field can point to more than one object type:
WhoIdpoints to a person: a Lead or Contact.WhatIdpoints to a non-person record: an Account, Opportunity, Case or a custom object that has activities enabled.
Because the fields are polymorphic, a query that needs a field from the related record has to filter by type or use TYPEOF. It can't use simple dot notation like a normal lookup.
Common mistakes
- Treating the label as the name. Code and integrations use the API name. A relabeled Account is still
Account. - Assuming a field exists in all orgs. Fields such as
Opportunity.ForecastCategoryNameor objects such asOrderdepend on features and editions. Code that references them fails to compile in orgs without them. - Forgetting required fields. Inserting a
LeadwithoutCompany, or anOpportunitywithoutStageNameandCloseDate, fails. - Hard-coding picklist values. Stage and status values are editable, and different orgs can have different values. Query
LeadStatusor read picklist metadata, as the lead conversion example does. - Ignoring Person Accounts. If they are enabled,
Accountqueries return both kinds of record, and some fields are empty for business accounts. - Expecting to delete a standard object or one of its required fields. You can hide fields from layouts and field-level security, but not remove them.
Exercise
A sales rep converts a lead named Grace Hopper at Navy Labs. Which records can the conversion create, which can it reuse, and what happens to the lead record afterwards?
Show answer
Conversion creates an Account and a Contact, or it can match and reuse existing ones. It creates an Opportunity only if you ask for one. The lead stays in the database with IsConverted set to true, and you can't edit it normally afterwards.
Exercise
You need to record that three different contacts are involved in one opportunity, each with a different role. Which standard object stores this, and what kind of object is it?
Show answer
OpportunityContactRole. It is a junction object between Opportunity and Contact, and each record stores one contact with one role for one opportunity.
Exercise
A teammate wants to remove the Amount field from Opportunity and delete the standard Case object because the org doesn't use them. Is that possible?
Show answer
Not fully. Standard objects can't be deleted, and Amount can't be removed from Opportunity. You can hide unused objects and fields from users with tabs, page layouts, app settings and field-level security.