Lesson 2 of 5 15 min read
Objects, fields and relationships
Model business data in Salesforce with standard and custom objects, choose field types, and connect objects with lookup and master-detail relationships.
In this lesson you will
- Create custom objects and choose suitable field types
- Recognise API names, record IDs and the __c suffix
- Choose between lookup and master-detail relationships
Objects, records and fields
An object is like a database table, a record is like a row, and a field is like a column. When the standard objects do not cover your business, you create custom objects. A training institute might add Course__c and Enrollment__c.
Every object and field has two names:
- a label that users see, such as "Course Fee"
- an API name that code and integrations use, such as
Course_Fee__c
Custom objects and fields end in __c. Standard ones, such as Account or Name, have no suffix.
Every record gets a unique record ID, such as 0015g00000AbCdEAAV. IDs are 15 characters (case-sensitive) or 18 characters (case-insensitive, safer for spreadsheets), and the first three characters identify the object.
Choosing field types
| Field type | Use it for | Example |
|---|---|---|
| Text | Short text | Course code |
| Number, Currency, Percent | Amounts and quantities | Fee, discount |
| Date, Date/Time | Calendar values | Batch start date |
| Checkbox | True or false | Fee paid |
| Picklist | A fixed list of choices | Level: Beginner, Intermediate, Advanced |
| Email, Phone, URL | Contact details, validated and clickable | Student email |
| Formula | A read-only value calculated from other fields | Fee including GST |
Picking the right type matters: Salesforce validates the input, reports can total and group correctly, and users get the right input control on the page.
Relationships
Relationships connect objects, much like foreign keys in a database.
| Lookup | Master-detail | |
|---|---|---|
| Coupling | Loose; the parent is usually optional | Tight; every detail must have a master |
| Deleting the parent | Children stay (the link is cleared) | Children are deleted too |
| Sharing and ownership | Child has its own owner and sharing | Child inherits sharing from the master |
| Roll-up summary fields | Not available | Available on the master (COUNT, SUM, MIN, MAX) |
For example, an Enrollment__c record means nothing without its course, so Enrollment → Course fits master-detail, and the course can show a roll-up count of enrolments. A contact's optional "referred by" contact fits a lookup.
Course__c (master) (contains Enrollment__c (detail)); Contact (master) (contains Enrollment__c (detail))
An object that has two master-detail relationships, like Enrollment__c linking a course and a student, is called a junction object. It models a many-to-many relationship: a student takes many courses and a course has many students.
Hands-on exercise
In your Developer Edition org, create a custom object Course with a Level picklist and a Fee currency field. Then create an Enrollment object with a master-detail relationship to Course and a lookup to Contact. Add a roll-up summary field on Course that counts its enrolments, create two enrolments and check that the count updates.
Knowledge check
3 questions • 70% to pass • Practice only, no certificate
Key concepts
- Objects are tables, records are rows and fields are columns.
- Custom objects and fields have API names ending in __c.
- Lookup relationships are loose; master-detail children depend on the parent and inherit its sharing.
- Junction objects with two master-detail relationships model many-to-many relationships.
