Salesforce Menu

sObjects in Salesforce

Sobjects are standard or custom objects that stores record data in the force.com database. There is also SObject datatype in apex that is the programmatic representation of these SObjects.
Developers referes to SObject and their fields by their API names.
Standard Object, Example :
  Account ac = new Account();
Custom Object, Example :
  merchandise__c mer = new merchandise__c();
* It’s noting but a API name.

Note : “__c” represents custom object/field created by us. By using this “__c” we can differentiate standard object/field and custom object/field.


Like in Java : there is an “Object” class/object which is used to hold any object of java similar way there is a “sObject” which is used to hold any object of salesforce below is the example :

An sObject is any object that can be stored in the Force.com platform database. These are not objects in the sense of instances of Apex classes; rather, they are representations of data that has or will be persisted

sObject is a generic abstract type that corresponds to any persisted object type. The generic sObject can be cast into a specific sObject type, such as an account or the Invoice_Statement__c custom object.

This creates an invoice statement, which corresponds to the Invoice_Statement__c custom object, without setting any fields and assigns the new invoice statement to an sObject.

sObject s = new Invoice_Statement__c();

same way you can downcast :

Invoice_Statement__c inv = (Invoice_Statement__c)s;

Adding our new merchandise to our Salesforce database?

1st way (Using Constructor)

  Merchandise__c m = new Merchandise__c(name=’kaka’);
  insert m;

Note : this same above way, also work in java too… so don’t thing its a new way of Salesforce.

2nd way (Using Setter method)

  Merchandise__c m = new Merchandise__c();
  m.name = ‘kaka’;
  insert m;

Subscribe Now