Wednesday, 6 December 2017

Salesforce Insert and Database.Insert

What is the difference between Insert and Database.Insert ?
Ans:
Actually both are same, DML statements.
Only difference we can see while processing the Bulk Data.
Ex: 5 records are processing for contact insert and LastName field is required for insertion,
3 have all required details and 2 record doesn't have.
Ex: All record added to list "lstContact"

Insert lstContact: 

It will not process any records,It rollbacks above 3 records also because of error thrown in 4th record

Database.Insert(lstContact,false) : 

It process all the 3 records and excludes 2 records.Partial DML operation is performed.
In Database we can see the 3 inserted records.

Database.Insert(lstContact,true) : 

It  is same as Insert,So it will not insert any record due to failure in other record.

opt_allOrNone :

Is the boolean variable used above.


Sample Execution Code :





No comments:

Post a Comment