0

here is my validation rule

    OR( 

NOT(REGEX(RIGHT(FirstName,LEN(FirstName)-1),"[\\p{L}\\s\\-.]*$")), 

NOT(REGEX(LEFT(FirstName,1),"[\\p{L}\\s.]*$")), 
(REGEX(LEFT(FirstName,1),"[\\p{L}\\s.]$")) 
)

I am Entering contact in test class

Contact con = new Contact();
con.firstname = 'Test';
con.lastname = 'Warner';
con.AccountId = acc.id;
insert con;

First Character is Capital and not special character allow. i'm following this validation but it throw error in test class is

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Special characters are not allowed in contacts First Name / Last Name: []

1 Answer 1

0

This has nothing to do with the test class. The validation seems to fail even while creating a contact with no special character in the first name.

The condition NOT(REGEX(LEFT(FirstName,1),"[\p{L}\s.]$"))) and (REGEX(LEFT(FirstName,1),"[\p{L}\s.]$"))) are contradicting conditions. One of them is going to be true. I think the third condition for the OR should be removed:(REGEX(LEFT(FirstName,1),"[\p{L}\s.]$")))

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .