Salesforce coding lessons for the 99%
Finally, Apex tutorials for point-and-click admins! Written by a self-taught Google engineer.
  • Beginner Tutorials
    • Apex
    • Certifications
    • Career Info
    • Technical Architect
    • Visualforce
    • Videos
  • Apex Academy
  • Success Stories
  • About Me
  • Misc
    • Mailbag
    • Challenges
    • Links
    • Login to my Org
Follow @dvdkliuor SUBSCRIBE!

What are objects and classes?

August 19, 2014

Preface – This post is part of the Object Oriented Thinking series.

We live in an epic galaxy full of objects and classes.
Surely, this universe was designed by a master programmer.

What’s a class? A class is a blueprint for making objects.
Classes describe an object’s general methods and ranges of properties.

What’s an object? An object is something created from a class.
Each object has its own specific properties and can use the methods defined in its class.

Example:

Class: The X-Wing
Methods: Shoot lasers, Hyperdrive, Open / close S-foils
Properties: Laser cannons (4), Hyperdrive engine, Deflector shield

While the class defines the general characteristics of X-Wings, an object defines one specific X-Wing: Luke Skywalker’s X-Wing is an Incom T-65 model with KX9 lasers and a class 1 hyperdrive engine.

Does this pattern seem familiar to you? …Salesforce revolves around objects and classes!
Think of standard and custom objects as classes, and individual records as objects.

Example:
Class: Lead
Methods: Convert, Create, Delete
Properties: Name (String), Company (String), Employees (Integer), Owner (User)

The difference between objects in Salesforce and objects in code is that objects in Salesforce are stored in Salesforce’s database, while objects in code only exist until your code finishes running.

So why do we need to use objects and classes? Same reason why Salesforce doesn’t combine the Lead, Opportunity, Contact, and Account classes into one – you’re more organized and in a better position to scale if you group things up into smaller components (classes) and relate them to each other, instead of combining everything into one massive entity. This concept is called modularizing.

Start thinking in terms of objects and classes, and you’ll see that everything revolves around them!

Next post: How to create an Apex class!

15 Comments
Arshadulla Shariff
February 3, 2017 @ 3:20 am

Hello David,
what if am creating class with Name Account .
for Eg:-
public class Account{
/*Data Members*/
public Account(){
/*some logic*/
}
}
Basically i assume i shouldn’t allow me, but i was wrong.
Any input how does it works. when i querying on object assigning to List.
List acclist = [Select Id,Name FROM Account limit 20];

Reply
    David Liu
    February 6, 2017 @ 8:46 pm

    Keep it simple and change the name LOL!

    SOQL doesn’t query classes, so your query is getting object records for sure!

    Reply
Zed
February 3, 2015 @ 5:59 am

“Think of standard and custom objects as classes, and individual records as objects”

that line just blew my fricken mind!!

Reply
    Austin Slack
    April 23, 2015 @ 1:48 pm

    It’s confusing that Salesforce calls things objects that are really more like classes. And also, that it calls permanent database tables objects, when objects in code are not so permanent. Thank you for addressing this source of confusion.

    Reply
Ajith
September 22, 2014 @ 3:02 am

Awesome job Dave. I haven’t seen such chapters which summarizes exactly what we need to know. Awaiting next topics.

Reply
    David Liu
    September 25, 2014 @ 7:27 pm

    Thank you!

    Reply
Chitra
September 18, 2014 @ 5:13 am

It is an awesome tutorial I have ever seen….
Am awaiting for the next topic..

Reply
hh
September 18, 2014 @ 2:05 am

when can we expect the furthur links, waiting for them?

Reply
Vladimir Valderama
September 16, 2014 @ 10:49 pm

Hi David,

I have read all your Tutorials and answered all of the Quizzes in every chapter. I appreciate all your effort in creating this website. I learned apex coding from these tutorials. I look forward for the pending Chapters to complete. Specially the chapters about scheduling apex triggers.

Thanks again.

Reply
Tasnim
September 4, 2014 @ 7:22 am

Awesome site on learning Apex. I’m waiting to read the additional topics; which doesn’t seem to have a link yet.

Thanks again…

Reply
    David Liu
    September 4, 2014 @ 7:01 pm

    hahaha sorry still in progress!

    Reply
rachel
August 22, 2014 @ 1:31 pm

wow david, you definitely summarise this very very well! I started reading the book you recommend, and couldn’t make heads or tails of it. I push through for a few chapters and figured i would go back from the beginning and perhaps grasp it then. But now reading this single post, i feel more prepared to start over and finally understand it

Reply
    David Liu
    August 24, 2014 @ 12:26 am

    Glad you liked it Rachel! It’s a big topic so I try to shave things down to the bare minimum to help understanding. In the book’s defense, they want you to have a 360 degree understanding of things – which is also good but a different philosophy than this site.

    Reply
Jose Maria Claramunt
August 20, 2014 @ 2:50 pm

Excelent analogy Dave! Thank you for keeping us novices educated!

Reply
    David Liu
    August 20, 2014 @ 10:34 pm

    Thanks Jose ^_^

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


*

*

Theme: Simple Style by Fimply