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
JohnTaylorUKJohnTaylorUK 

Help with very basic test class

Hi All,

 

I have a very basic trigger that moves a text field into an email field, to enable a workflow to send out an email to this address.

 

I would like to write a test class for this trigger to help keep everyting in order

 

 

trigger UpdateEmailFieldWithRealEmail on Offer__c (before insert,before Update)

{
for (Offer__c OFF : Trigger.new)

    {
OFF.candidates_Email_Address_For_Chases__c = OFF.Candidates_Email_Address__c;
    }
    
}

 

 

The trigger itself is very simple and does what I needed but I could now really do this help to write the test class

 

Any pointers would be great

 

Thanks

 

John

Shashikant SharmaShashikant Sharma

This is your test class

 

 

@isTest
private static class testTriggerUpdateEmailFieldWithRealEmail  {

private static TestMethod void testInsertTrigger() {
Offer__c objOfficer = new Offer__c(Candidates_Email_Address__c = 'test@testemail.com');
//assign all req fields values to objOfficer if any, don't need to provide value to candidates_Email_Address_For_Chases__c field

test.startTest();

insert objOfficer;
system.assertEquals(objOfficer.Candidates_Email_Address__c , objOfficer.candidates_Email_Address_For_Chases__c);
test.stopTest();
}

private static TestMethod void testUpdateTrigger() {
Offer__c objOfficer = new Offer__c(Candidates_Email_Address__c = 'test@testemail.com');
//assign all req fields values to objOfficer if any, don't need to provide value to candidates_Email_Address_For_Chases__c field
insert objOfficer;

test.startTest();

objOfficer.Candidates_Email_Address__c = 'test@updatedEmail.com';
update objOfficer;
system.assertEquals(objOfficer.Candidates_Email_Address__c , objOfficer.candidates_Email_Address_For_Chases__c);
test.stopTest();
}
}

 

See this for more :http://forceschool.blogspot.com/search/label/Apex%20Triggers