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!
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];
Keep it simple and change the name LOL!
SOQL doesn’t query classes, so your query is getting object records for sure!
“Think of standard and custom objects as classes, and individual records as objects”
that line just blew my fricken mind!!
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.
Awesome job Dave. I haven’t seen such chapters which summarizes exactly what we need to know. Awaiting next topics.
Thank you!
It is an awesome tutorial I have ever seen….
Am awaiting for the next topic..
when can we expect the furthur links, waiting for them?
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.
Awesome site on learning Apex. I’m waiting to read the additional topics; which doesn’t seem to have a link yet.
Thanks again…
hahaha sorry still in progress!
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
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.
Excelent analogy Dave! Thank you for keeping us novices educated!
Thanks Jose ^_^