function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VempallyVempally 

Use of the term <sObject> in batch apex...

Hi Everyone,

In Batch Apex can anyone explain me what this <sObject> is needed for. what exactly it does...?

 
Best Answer chosen by Vempally
Manmohan SinghManmohan Singh
Dear Vempally,

An sObject is any object that can be stored in the Force.com platform database .  sObejct is a generic  object which can be cast into any type of Standard/CO objects (Account, Contact, Opportunity, CO, etc), this helps salesforce to store data at back end database.

Let say you are writing apex class for a custom object (Customer Temp Table, so please make sure you cast your list of sObejcts into CustomerTempTable__c, below code is the sample code which will cast sObejct into Custom Obejct.

global void execute(Database.BatchableContext BC, List<sObject>scope){
      //Casting scope list of records into Custom Obejct.             
      List<CustomerTempTable__c> listTempCustomers = (List<CustomerTempTable__c>)scope;  
       }
 

All Answers

Manmohan SinghManmohan Singh
Dear Vempally,

An sObject is any object that can be stored in the Force.com platform database .  sObejct is a generic  object which can be cast into any type of Standard/CO objects (Account, Contact, Opportunity, CO, etc), this helps salesforce to store data at back end database.

Let say you are writing apex class for a custom object (Customer Temp Table, so please make sure you cast your list of sObejcts into CustomerTempTable__c, below code is the sample code which will cast sObejct into Custom Obejct.

global void execute(Database.BatchableContext BC, List<sObject>scope){
      //Casting scope list of records into Custom Obejct.             
      List<CustomerTempTable__c> listTempCustomers = (List<CustomerTempTable__c>)scope;  
       }
 
This was selected as the best answer
Pruthvi KankunthalaPruthvi Kankunthala
@Vempally : sObject is a generic object which can be of any type . In batch apex when they use List<sObject> as an argument , it means that you will get all the types of record in there . it's your wish which one you want to take and process further . Hope it's clear !!!
Amit Chaudhary 8Amit Chaudhary 8
Hi Vempally,

Execute method
global void execute(Database.BatchableContext BC, list<P>){}
A list of sObjects, such as List<sObject>, or a list of parameterized types. If you are using a Database.QueryLocator, use the returned list.
So this Sobject will support all Object type in salesforce
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_batch_intro.htm


Please check below post for sObject
An sObject is any object that can be stored in the Force.com platform database
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex6_1.htm

sObject refers to any object that can be stored in the Force.com platform database. An sObject variable represents a row of data and can only be declared in Apex using the SOAP API name of the object
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SObjects.htm

Let us know if this will help you
 
Prasanth Reddy MPrasanth Reddy M
@ Vempally, we use batchapex, to do a DML operation(Insert/Update/Delete/Undelete) on large volumes of data, <Sobject> represents the object for which you want the DML operation to be performed. For Instance adding 20000 campaign members to a campaign.