Created
April 12, 2018 19:19
-
-
Save olgaloza/b08ee5e061ca620e744a186ae7b65e1f to your computer and use it in GitHub Desktop.
Test Apex Triggers Challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private class TestRestrictContactByName { | |
@isTest static void testInvalidName() { | |
//try inserting a Contact with INVALIDNAME | |
Contact myConact = new Contact(LastName='INVALIDNAME'); | |
insert myConact; | |
// Perform test | |
Test.startTest(); | |
Database.SaveResult result = Database.insert(myConact, false); | |
Test.stopTest(); | |
// Verify | |
// In this case the creation should have been stopped by the trigger, | |
// so verify that we got back an error. | |
System.assert(!result.isSuccess()); | |
System.assert(result.getErrors().size() > 0); | |
System.assertEquals('Cannot create contact with invalid last name.', | |
result.getErrors()[0].getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just reporting a silly mistake I made. Wanted to post this here in case anybody else makes the same mistake I did.
I was getting the error:
and found that I was missing the
false
argument in theDatabase.insert()
statement (line 11).