Skip to main content

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 typeUse it forExample
TextShort textCourse code
Number, Currency, PercentAmounts and quantitiesFee, discount
Date, Date/TimeCalendar valuesBatch start date
CheckboxTrue or falseFee paid
PicklistA fixed list of choicesLevel: Beginner, Intermediate, Advanced
Email, Phone, URLContact details, validated and clickableStudent email
FormulaA read-only value calculated from other fieldsFee 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.

LookupMaster-detail
CouplingLoose; the parent is usually optionalTight; every detail must have a master
Deleting the parentChildren stay (the link is cleared)Children are deleted too
Sharing and ownershipChild has its own owner and sharingChild inherits sharing from the master
Roll-up summary fieldsNot availableAvailable 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.

Enrollment__c is a junction object with two masters

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

  1. 1.Which API name belongs to a custom field?
  2. 2.Which feature is available only with a master-detail relationship?
  3. 3.What do you call an object that links two objects with two master-detail relationships to model many-to-many?
0 of 3 answered

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.