Introduction to objects in salesforce


Salesforce objects are not ordinary objects as we seen in Java,c++ and other programming languages, so what make salesforce object different from objects of other programming languages. First we need to see definition of the object in Java and later we compare it with object in salesforce.

Objects in Java
Object is a identity which have state and behaviour where state representing a variable and behaviour showing function

In Java object have some behavior and state for an example snow dog is object of class dog, so let’s define class dog.

public class Dog{
   String breed;
   int age;
   String color;

   void barking(){

This is general Java class of dog and from this class many object or many kinds of dog can be derived which do have different kind of breeds and color so we can define an object of this class using below syntax.

Dog dobject=new Dog();   // new Dog() is object of class dog refer by variable dobject of type Dog

This is about an object in Java now let see what is object in salesforce as in the beginning I told you that objects in salesforce are quite different things from object in Java so let’s see.

Salesforce Object
Salesforce object is like container or table which holds records in itself,if you are familiar with database then you can consider salesforce object as Table which hold records in it.

Salesforce object are further divided in two parts one is custom objects and other is standard objects. Let us try to understand this concept as Java do some predefined set of classes similar to that salesforce have some predefined object for specific functionality related to CRM and other then any object we create in salesforce organization is a custom object, please take a look at the below table for more difference in them

Standard ObjectCustom Object
Predefine Objects in salesforceObjects that user create in salesforce
Examples : AccountContact e.t.c
Any object other then standard object like positionAPI Name : Account
ContactAPI Name: Position__c

Mostly novice people create a new custom object if they required object other than standard object but before creating any new object we should do fit gap analysis so we can use standard objects instead of custom objects by renaming objects and field according to our business requirement.

How to create a custom object in salesforce

it is very easy to create a new custom object you just need to go to app setup->Create->objects ,see below picture for more information.


When you click on object it will redirect to a new page and in that page you will see a button to create a new custom object so click on that and it will redirect you to a page where you need to fill out all the details to create a new object, for more information what to fill in those fields take a look at this link
that’s how we can create a new custom object in salesforce, lets us take an example we have created a custom object position and its API name is position__c(all the custom objects append with __c) and we have also created two field in it title whose API name is Name and another field is start date whose API name is Start_Date__c,each field have their unique ID we can need ID of this filed in apex some time you can also look at my post on how to get an ID of the field in salesforce.

Use Custom objects and custom fields in Apex

As we have seen above in Java example that object of class is created like Dog dobject=new Dog(); similar to that we create object of position,so it syntax would be like

position__c pobject=new position__c();  //New object get created with name pobject'Test';   //Refer field name with its API name;
insert pobject;  //Inserting data in the position object

The code at line no. 1 would be same like Java object but here this object will have access to all the fields of position objects as Java object have access to state(variable) of the class,that’s how we can use custom objects and its field in the apex, similarly to that we can use standard objects in Apex. Summary of this post what are objects in Java and salesforce and how they are differ and what type or kind objects we have in salesforce and how to use or refer those objects and fields in apex. I hope you like my post if you have any query please do leave a comment in the comment box below and don’t forget to subscribe to my blog and social networking pages.

Related Articles :

Speak Your Mind



This site uses Akismet to reduce spam. Learn how your comment data is processed.