Advertisement
matthewpoer

SF APEX trigger and test fails

Jan 9th, 2013
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. trigger GoogleScholarResults on Lead (before insert, before update) {
  2.  
  3.     for(Lead lead_record: Trigger.new){
  4.         if(lead_record.FirstName == 'Matthew' && lead_record.LastName == 'Poer'){
  5.             lead_record.FirstName = 'Matt';
  6.         }
  7.     }
  8.  
  9. }
  10.  
  11. // and the corresponding test, which fails
  12.  
  13. @isTest
  14. private class TestGoogleScholarResults {
  15.  
  16.     static testMethod void testMattPoer(){
  17.         // setup the leads
  18.         Lead lead_record_matthew_poer = new Lead(FirstName = 'Matthew',LastName = 'Poer',Company = 'PSI');
  19.         Lead lead_record_ron_fisher = new Lead(FirstName = 'Ron',LastName = 'Fisher',Company = 'PSI');
  20.        
  21.         // start test, insert leads, stop test
  22.         Test.startTest();
  23.         insert lead_record_matthew_poer;
  24.         insert lead_record_ron_fisher;
  25.         Test.stopTest();
  26.  
  27.         // assert that Ron is still Ron
  28.         List<Lead> rons = [select FirstName,LastName from Lead where LastName = 'Fisher' and Company = 'PSI'];
  29.         for(Lead ron: rons){
  30.             system.assertEquals('Ron', ron.FirstName, 'The name should have been Ron');
  31.         }
  32.        
  33.         // assert that Matthew became Matt
  34.         List<Lead> matthews = [select FirstName,LastName from Lead where LastName = 'Poer' and Company = 'PSI'];
  35.         for(Lead matthew: matthews){
  36.             system.assertEquals('Matt', matthew.FirstName, 'The name should have been adjusted to Matt, not Matthew');
  37.         }
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement