0

I'm trying to create a validation rule that ensures that a field does not equal the logged in users email. Here is what I have written:

and ( RecordTypeId ='0124p0000005SNfAAK', Contact_Email__c = $User.Email )

I don't receive any errors, but the rule does not seem to be firing. Like, I can go create a record and put my own email in the field and it doesn't throw an error. It should be displaying my error message about how the Contact Email needs to be different from your email.

I think my issue might be that contact_email__c is a text field - does it not let me compare text fields to email fields?

2
  • Your question lacks some information that would be useful in assisting you. What is the behavior you observe, and how does it diverge from your expectation? – Adrian Larson Mar 9 at 16:11
  • Good point - I don't receive any errors, but the rule does not seem to be firing. Like, I can go create a record and put my own email in the field and it doesn't throw an error. It should be displaying my error message about how the Contact Email needs to be different from your email. – Michael Mar 9 at 16:19
0

The solution was that 18 character recordtypeids are not recognized in validation rules. You need to use the 15 character ID

1
  • 4
    you should be using $RecordType.xxx; never use hardcoded ids – cropredy Mar 9 at 17:18
0

Never use Hardcoded Id's. Developers should know that it is not a best practice to hardcode IDs in code, as documented in the Salesforce Developers site.

The reason why you want to avoid hardcoding Salesforce IDs is that when the new record that your configuration item is referencing is created in a sandbox, and then created in every sandbox leading up and including Production, that new record’s Salesforce ID will not be the same. You will need to update each reference of this hardcoded Salesforce record ID in every sandbox or production. As a result, you have different versions of your formula, validation rule. process builder or flow, etc. in your regions.

In your case you can use

$RecordType.Name OR $RecordType.DeveloperName
$RecordType.Name matches with 'Record Type Label' and
$RecordType.DeveloperName matches with 'Record Type Name'

Where possible, rather than using the ID, reference it by something that is the same in all regions and less likely to change, such as the API name or field label. If Salesforce will only take the ID then you can use Custom Label. Custom field is just a custom text field that isn’t object specific. It can be called anywhere in Salesforce. In other words, it is not object or configuration type specific and can therefore be leveraged throughout the org.

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.