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: []

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.]$")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.