Email value is saved without parentheses (label) when using DML

When an email contains a label enclosed in parentheses, the value can be saved as typed in via SF UI. (Note: the email value “as is” is only seen when in Edit mode.) However, when the record is saved using Apex or Query Editor on Developer Console, the content in parentheses is lost.

For example, a user specifies an email as: foe@testorg.com (Foe Test)
When saving the record via SF UI, the result is: foe@testorg.com (foe test)
When saving the record using Apex, the result is: foe@testorg.com

Why is there inconsistency in saving an email value. How can we save an email containing parentheses using Apex?

Account acc = new Account(name = 'Test Email');
insert acc;

String email = 'testbill0@billing.com (any label)';
Contact c = new Contact (lastName = 'Test', accountId = acc.id, email = email);
insert c;

Contact cDb = [
    SELECT
        id,
        accountId,
        name,
        email
    FROM Contact
    WHERE id = :c.id
][0];

System.assertEquals(c.email, cDb.email);

Answer

The inconsistency could be a bug that has been fixed. Cannot replicate it now. The result is “foe@testorg.com” in both SF UI and Apex.

Attribution
Source : Link , Question Author : RadDeveloper , Answer Author : Chun

Leave a Comment