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
ZoomVZoomV 

Simple trigger test code

I've written this super easy trigger which only sets a date. I'm still learning how to write test code, so I was wondering if anybody could show me what it would be like for something this simple :

 

trigger SetContractEndDates on Contract_Terms__c (before insert, before update) {

  for (Contract_Terms__c ct : Trigger.new) {
          if (ct.Auto_Renewal_Contract_End_Date__c== null)
          ct.Overall_End_Date__c= ct.Contract_End_Date__c;
        else
          ct.Overall_End_Date__c = ct.Auto_Renewal_Contract_End_Date__c;  
  }
}

 

Thank you very much.

Best Answer chosen by Admin (Salesforce Developers) 
Devendra@SFDCDevendra@SFDC

Hi,

 

@isTest
private class Contract_Terms__cTriggerTest
{

	static TestMethod void Contract_Terms__cTriggerTest1()
	{
		Test.startTest();
// Insert Contract_Terms__c record Contract_Terms__c obj = new Contract_Terms__c(Name = 'test record 001', Contract_End_Date__c = System.Today() +1, Auto_Renewal_Contract_End_Date__c = System.Today() + 2); insert obj;
Test.stopTest(); } }

 You can also go through the documentation.

 

http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

 

 

All Answers

Devendra@SFDCDevendra@SFDC

Hi,

 

@isTest
private class Contract_Terms__cTriggerTest
{

	static TestMethod void Contract_Terms__cTriggerTest1()
	{
		Test.startTest();
// Insert Contract_Terms__c record Contract_Terms__c obj = new Contract_Terms__c(Name = 'test record 001', Contract_End_Date__c = System.Today() +1, Auto_Renewal_Contract_End_Date__c = System.Today() + 2); insert obj;
Test.stopTest(); } }

 You can also go through the documentation.

 

http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

 

 

This was selected as the best answer
ZoomVZoomV

Thank you very much Devendra. I really appreciate it.

Devendra@SFDCDevendra@SFDC
Hi,

Glad the solution has worked for you.