# Data Model — Objects, Fields & Relationships

> Standard vs custom objects, field types, lookup vs master-detail, junction objects and external IDs.

**Track:** admin · **Category:** Platform Basics · **Topics:** Data model, Relationships, Objects, Fields

Read on the site: https://www.forcechallenges.com/notes/data-model

## Objects

- **Standard objects** ship with Salesforce: Account, Contact, Lead, Opportunity, Case, User…
- **Custom objects** end in `__c` (API name `Invoice__c`), custom fields too (`Discount__c`).
- Each record has an 18-character case-insensitive **Id**; the first 3 characters identify the object (`001` Account, `003` Contact, `006` Opportunity).

## Common field types

| Type | Example use |
|---|---|
| Text / Text Area / Long Text Area | Names, notes |
| Number / Currency / Percent | Quantities, amounts |
| Picklist / Multi-select picklist | Stage, Industry |
| Checkbox | Active? |
| Date / Date/Time | Close date, created date |
| Formula (read-only) | `Amount * Probability / 100` |
| Roll-Up Summary (master-detail parent only) | Count/sum of child records |
| Lookup / Master-Detail | Relationships |
| Auto Number | `INV-{0000}` |

## Lookup vs Master-Detail

| | Lookup | Master-Detail |
|---|---|---|
| Coupling | Loose | Tight (child can't exist without parent) |
| Required | Optional (can be required) | Always required |
| Delete parent | Child kept (field cleared) or blocked | **Children deleted** (cascade) |
| Owner / sharing | Child has its own owner and sharing | Child inherits owner & sharing from parent |
| Roll-up summary fields | ❌ (use Flow/Apex) | ✅ |
| Per object | Up to 40 relationship fields total | Up to 2 master-detail |

## Junction objects (many-to-many)

To relate many Students to many Courses, create **Enrollment__c** with two master-detail fields (Student, Course). Each Enrollment record links one student to one course.

```
Student__c ──< Enrollment__c >── Course__c
```

The first master-detail field becomes the "primary" parent (record ownership, look and feel).

## Hierarchical & other relationships

- **Self-relationship**: Account → Parent Account.
- **Hierarchical**: only on User (e.g. Manager).
- **External lookup**: to external objects (Salesforce Connect).

## External IDs

Mark a text/number/email field as **External ID** (and often Unique) to:
- **Upsert** records from another system without knowing Salesforce Ids.
- Speed up searches and SOQL filters (the field is indexed).

## Schema Builder

**Setup → Schema Builder** gives a drag-and-drop ERD of objects and relationships — handy for explaining a data model in an interview.

## Interview questions

1. *Lookup vs master-detail — give three differences.*
2. *How do you model a many-to-many relationship?* → Junction object with two master-detail fields.
3. *Can you convert a lookup to master-detail?* → Yes, if every existing record has a value in the field.
4. *What is an external ID used for?* → Upserts/integrations and indexed lookups.

---
Source: ForceChallenges · last updated 2026-10-03
