Sunday, February 8, 2015

What is the difference between Insert and Database.Insert in salesforce.


Insert
If we use the DML statement (insert), then in bulk operation if error occurs, the execution will stop. In that case Apex code throws an error and none of the record is inserted to the database.


Database.Insert
If DML database methods (Database.insert) used, then if error occurs the remaining records will be inserted / updated means partial DML operation will be done. The only record throwing an error will not be inserted / updated.

So you should use Database.insert in any bulk dml operation if you are not monitoring the code properly

Regards,
Naveen,
http://www.autorabit.com/.

How to delete data from Recycle bin in salesforce.

When we use DML statement delete the data is deleted from that particular object but it is available in recycle bin to restore.

 
data1 =[Select id from Object1__c];
delete data1;


If we execute above code the data will be removed from Object data base, but will be availble in recycle bin.

If  we want to remove data from recycle bin below code will works.

data1 =[Select id from Object1__c];
delete data1;

DataBase.emptyRecycleBin(oldDL); 



Regards,
Naveen.
http://www.autorabit.com/