Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger GoogleScholarResults on Lead (before insert, before update) {
- for(Lead lead_record: Trigger.new){
- if(lead_record.FirstName == 'Matthew' && lead_record.LastName == 'Poer'){
- lead_record.FirstName = 'Matt';
- }
- }
- }
- // and the corresponding test, which fails
- @isTest
- private class TestGoogleScholarResults {
- static testMethod void testMattPoer(){
- // setup the leads
- Lead lead_record_matthew_poer = new Lead(FirstName = 'Matthew',LastName = 'Poer',Company = 'PSI');
- Lead lead_record_ron_fisher = new Lead(FirstName = 'Ron',LastName = 'Fisher',Company = 'PSI');
- // start test, insert leads, stop test
- Test.startTest();
- insert lead_record_matthew_poer;
- insert lead_record_ron_fisher;
- Test.stopTest();
- // assert that Ron is still Ron
- List<Lead> rons = [select FirstName,LastName from Lead where LastName = 'Fisher' and Company = 'PSI'];
- for(Lead ron: rons){
- system.assertEquals('Ron', ron.FirstName, 'The name should have been Ron');
- }
- // assert that Matthew became Matt
- List<Lead> matthews = [select FirstName,LastName from Lead where LastName = 'Poer' and Company = 'PSI'];
- for(Lead matthew: matthews){
- system.assertEquals('Matt', matthew.FirstName, 'The name should have been adjusted to Matt, not Matthew');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement