Design the Data Model
By the end of this lesson, you'll be able to:
- Design custom objects and fields for a library system
- Decide which parts of the system belong in the data model vs in Apex service classes
- Apply the "find the nouns" technique from Module 12 to Salesforce object design
Prerequisites: Module 21: "SOSL"
What we're building
Over this module you'll build a small library system, working against real Salesforce custom objects, that:
- Tracks books in a catalog.
- Records checkouts and returns.
- Lets a librarian query and search the catalog.
- Handles real-world edge cases — a book that's already checked out, a member trying to return a book they didn't borrow.
This is the course's first project working against actual sObjects rather than pure in-memory classes — every SOQL, DML, and SOSL lesson from Modules 18-21 gets put to real use here.
Designing the data model
Applying Module 12's "find the nouns" technique to "a library tracks books, and members check books out and return them":
Book__c
- Title__c (Text)
- Author__c (Text)
- ISBN__c (Text, External ID)
- Is_Checked_Out__c (Checkbox)
Checkout__c
- Book__c (Lookup to Book__c)
- Member_Name__c (Text)
- Checkout_Date__c (Date)
- Return_Date__c (Date, blank until returned)
This is Module 18's custom object and custom field patterns directly applied — every field name ending in __c, exactly as covered there.
What belongs in the data model vs in Apex
The data model above only stores facts — it doesn't decide "is this book available to check out?" That decision belongs in Apex code (the next lesson builds a LibraryService class for exactly this), which reads the stored facts and applies business rules to them. Keeping the data model itself simple and the logic in Apex is a deliberate separation, one this course revisits more formally in a much later Enterprise Architecture module.
Exercise
As a comment, decide whether "the number of days a book was checked out" belongs as a stored field or as something calculated in Apex from Checkout_Date__c and Return_Date__c.
Show hint
Think about whether storing it risks it going stale.
Design the Data Model Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
Before writing any code, this lesson designs the two custom objects a library system needs — Book__c and Checkout__c — and decides which responsibilities belong in the data model versus in Apex.