Showing posts with label DML Statements. Show all posts
Showing posts with label DML Statements. Show all posts

Thursday, 8 December 2016

SQOL to know Code coverage in Salesforce


Salesforce provides developers a way to find out Codecoverage details. 
Write a SQOL by using  “ApexCodeCoverageAggregate”  to know Code coverage for all Apex Classes and Apex Triggers withing fraction of seconds. 

* SOQL :

SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate


Tips : 

* Use of "ORDER BY" clause will let you have your result more presentable.

e.g. 

SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate ORDER BY  ApexClassOrTrigger.Name ASC




* Make sure that you have enabled "Use Tooling API" check box in Developer Console to execute following query.  (see following image - Red circle)




Monday, 12 October 2015

Difference between database.insert and insert




* insert is the DML statement which is same as databse.insert.

* However, database.insert gives more flexibility like rollback, default assignment rules etc.

* We can achieve the database.insert behavior in insert by using the method    setOptions(Database.DMLOptions)

* Important Difference:

If we use the DML statement (insert), then in bulk operation if error occurs -
the execution will stop and Apex code throws an error which can be handled in try catch block.

If we use the DML database methods (Database.insert), then if error occurs
- the remaining records will be inserted / updated means partial DML operation will be done.