APEX CODING TIPS
Assigning Query to string variable for using as a
parameter....
[SELECT ID FROM Merchandise__c
WHERE NAME = 'Coffeemaker'] to a string for passing in to a method
String s= 'select id from Merchandise__c where name = \' coffee maker \'';
\’ – will be counted for ‘ when the string is evaluated.
|
Public
List<sObject> sObjectVariable{get;set;}
sObjectVariable
= new List<sObject>();
|
implements
keyword
is used to indicate interface implementation
static keyword
indicates a class variable (or method) accessible without an instance of the
class
final
keyword
indicates a constant.
To deliberately cause the DMLException to improve your code coverage and check the functionality of the exception handling.
try {
// If you can't manipulate the Apex methods input or database state to cause a
// DMLExcpetion then you can deliberately cause the DMLException to improve your
// code coverage and check the functionality of the exception handling.
// You could also use a flag set from your test method to indicate that the
// exception should be thrown
if(Test.isRunningTest()) {
// Cause DMLException
insert new Lead();
}
} catch (DMLException ex) {
// Existing exception handling.
}
Comments
Post a Comment