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';
Every custom object's API name ends in __c (for "custom") — this is how Apex and Salesforce distinguish Course_Enrollment__c (something an org's team built) from Account (something Salesforce built in). Custom fields follow the same convention, seen here on Student_Name__c and Course_Name__c.
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);
Aside from the __c suffix, a custom object works in Apex exactly like a standard one — new, dot notation for fields, all identical. 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.
Custom Objects 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
A custom object is a data structure an org's admins or developers define themselves, for business data standard objects don't already cover.