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
Hugo_BHugo_B 

Need help on how to test a trigger

I have created a trigger which performs a calculation on a custom object "after insert, update or delete".

 

I have a Sandbox (whoopee); I can deploy the trigger to the sandbox, but I have no clue how to TEST and Deploy to production.

 

 

Can anyone point me in the right direction on what to read?  I have looked at the APEX Code developer guide, but I don't understand how to run a test and deploy the trigger.

 

I could be just plain stupid, but I would have hoped to find some "here are the steps to deploy a trigger from eclipse" type instructions but I can't find any.

 

PS - if I am just plain stupid, then I may be doomed ;)

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

In order to test the trigger you need to write a testMethod containing some code that carries out the insert/update/delete of the custom object and verifies via asserts that the calculation results are correct.  You then run the test by selecting the name of the class containing the test code, right clicking and choosing Force.com -> Run Tests from the resulting popup menu.

 

You won't be able to deploy to production until you have tests that cover 75% of the code that you are trying to deploy.

 

Once you have the code coverage, you can deploy the trigger from Eclipse by right clicking the trigger name and choosing Force.com -> Deploy to Server from the popup menu.

 

You will then go through a deployment "wizard", that allows you to deploy to a different server to the one you are developing against.