You need to sign in to do that
Don't have an account?

How to write a Test Case for the following Application
Hi,
I have written an Apex class and a Trigger associated with it, to get the user defined Auto Number in string format. I have got the desired output, but when I am writing the Test Cases, I am getting the Code Coverage as 0%. In order to place the application to the production mode we are suppose to get a minimum of 75 % code coverage. I am posting the Trigger, Apex class and the Test Case. So could any one please suggest a solution for the this problem so that code coverage percentage is greater than 75 %.
Trigger
trigger DRTrigger on DR__c (before insert)
{
DR__c [] dr = Trigger.new;
DRNumber.getDRNum(dr);
}
Apex Class
public class DRNumber
Test Case @isTest |
Your test defines an empty list, then attempts to iterate through the empty list. As a result, the code does nothing and performs no coverage of your trigger.
Your "class" is also incorrect; do not place queries inside a loop. It is considered "not bulk safe."
Try this out:
Trigger
Class
Test
It's fairly late here, so please take this post with a grain of salt (or coffee, perhaps). The main idea here is to outline how I would recommend that you write your trigger. It needs to actually perform a database insert in order to run the trigger. Your posted code does not perform any testing at all because it runs against an empty list of records.
Also note that the trigger has to run in "bulk" or you risk user exceptions when you perform imports, data migrations, etc.