Intermediate 20 min read

Custom Objects

By the end of this lesson, you'll be able to:

  • Explain what a custom object is and when one is needed
  • Recognize the __c suffix convention for custom objects and fields
  • Reference a custom object in Apex the same way as a standard one

Prerequisites: "Standard Objects"

When standard objects aren't enough

Account and Contact cover common business concepts, but a school's Salesforce org needs to track something like "Course Enrollment," and a car dealership needs "Vehicle Trade-In" — neither exists as a standard object. Custom objects fill this gap: any business-specific data structure an org actually needs.

The __c naming convention

Course_Enrollment__c enrollment = new Course_Enrollment__c();
enrollment.Student_Name__c = 'Amara Nkosi';
enrollment.Course_Name__c = 'Apex Fundamentals';
  1. Course_Enrollment__c enrollment = new Course_Enrollment__c(); — every custom object's API name ends in __c (for "custom") — this is how Apex and Salesforce distinguish something an org's team built from Account (something Salesforce built in).
  2. enrollment.Student_Name__c = 'Amara Nkosi'; — custom fields follow the same convention.
  3. enrollment.Course_Name__c = 'Apex Fundamentals'; — another custom field, same suffix.

Used identically to a standard object

Course_Enrollment__c enrollment = new Course_Enrollment__c();
enrollment.Student_Name__c = 'Ben Dlamini';

System.debug(enrollment.Student_Name__c);
  1. Course_Enrollment__c enrollment = new Course_Enrollment__c(); — aside from the __c suffix, a custom object works in Apex exactly like a standard one.
  2. enrollment.Student_Name__c = 'Ben Dlamini'; — new and dot notation, all identical to Account.
  3. (blank line)
  4. System.debug(enrollment.Student_Name__c); — logs the value. The distinction matters for naming, not for how you write code against it.

Exercise

As a comment, name a business scenario (not Account, Contact, Opportunity, or Case) that would need a custom object, and give it a plausible __c API name.

Show hint

Think of something specific to one kind of business.

APEX

Custom Objects Quiz

1. What does the __c suffix indicate?

Log in to submit the quiz and save your score.

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

A custom object is a data structure an org's admins or developers define themselves, for business data standard objects don't already cover.