Skip to main content
added 12 characters in body
Source Link
Lance Shi
  • 13k
  • 14
  • 86
  • 186

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

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

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

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

Source Link
cloudZigZag
  • 1.4k
  • 3
  • 31
  • 81

Validation Rule Throwing error in test class

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