function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Apex codingApex coding 

How to write testcases for triggers

Hi
I have wriiten some classes and triggers whcih contain Apex coding
To deploy that on to production or Sandbox of Salesforce
 
Salesforce.com recommends that at least 75% of your Apex scripts should be covered by unit tests, and all triggers should have some test coverage.
 
 
I have wriiten test classes for classes and I dont know How to write test cases for Triggers
what do you mean by " all triggers should have some test coverage."
 
can any one help me in this  regard
 
regards
sunil
 
Jon Mountjoy_Jon Mountjoy_
See this forum post, as it has a simple trigger test that should help you:

http://community.salesforce.com/sforce/board/message?board.id=apex&thread.id=4492

Regards,
Jon
dmchengdmcheng
Your test methods should create some dummy records for the object with the trigger, then you should execute the DML statement(s) that will activate the trigger.

For example, I have a trigger on "after insert" for Membership Payment, so my test method creates a list of 20 dummy records and then I just execute an "insert" command.  Remember that test methods do not make any changes to the actual database - it seems they use a virtual copy that merges your existing data plus any changes you cause within the test method.  For example, if your test method inserts a new Contact record and then selects the ID of that record, you will get a valid ID even though it doesn't exist in your actual database.

David