0

I'm using On-Demand email to case. For automatic case creation from incoming email on several email adresses. I have extended functionality to enable automatic creation of contacts based on other integrations as well. IMPORTANT - Emails are not Unique identifiers. Only for specific record types. Example below illustrate my need to ensure only specific case record types can be related to specific contact record types. Like: VIP Cases <->VIP Contacts Other Cases <-> Other Contacts

This works fine with my automated Apex trigger/class logic on Case-object (after insert). Problem occurs when I add validation rules or lookup filters which enforces that cases and contacts need to match. It seems like email-to-case functionality might add the first match (contact found from a search for emailadress), to the case. And afterwards my logic corrects it, if the record types doesn't match. So the auto-creation fails due to validation rules or lookup filter rules.

I have tried to implement a validation rule which only ran if (isnew) or if custom field (validate__c) was set to true, and then setting this field to true in the trigger. But in order to neglect this validation rule for email-to-case, I defaulted the validate__c to "false". This will then also apply to manually created cases. Which will never be "validated" then.

Any ideas on how to implement validation rule or lookup filter, which will not affect this email-to-case logic?

2

Email to Case runs on system context, While creating the case from email owner would be System Administrator. So you can add code to your validation rule to bypass the rule for certain profile. The validation rule will not if user is System Administrator.

$Profile.Name <> 'System Administrator'

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.