Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a catch-22 issue that I have been unable to test fully. I am using a W2L form to input lead information remotely and its well documented that using an email field can cause the record to fail to insert since internal salesforce validation seems to happen before the record is sent to the trigger.

    TestMe test = new TestMe();
    test.initializeLead(false);
    test.lead.email = 'i will break';
    insert test.lead;

RESULT:

    12:42:28.494 (1494981000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email: invalid email address: i will break: [Email]

so I'm asking someone to confirm whether or not this is a the case of an un-testable situation where we cannot insert a lead with an invalid email from a unit test but can have the case where an email can be custom validated through a trigger or validation when inserted through W2L?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Correct. Inserting a Lead via unit tests will require you to have a properly formatted email address.

With Web-To-Lead the system doesn't run validation against the email address of any kind, meaning any value submitted will be input. You can work around this by creating a Validation Rule to validate the email address.

Something like this...

NOT(CONTAINS(Email,'@'))

You can get more complicated an validate the suffix is .com, etc. But I think this should help you get started.

share|improve this answer
    
thanks for the confirmation, and I am using a regexp to do the validation. String emailPattern = '([a-zA-Z0-9_\\-\\.]+)@((\[a-z]{1,3}\\.[a-z]{1,3}\\.[a-z]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.‌​)+))([a-zA-Z]{2,4}|[0-9]{1,3})'; if(lead.email != null && Pattern.matches(emailPattern, lead.email) == false) –  ebt Feb 20 '13 at 18:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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