function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Renee ProrokRenee Prorok 

Need help on custom validation rule upon case creation - current rule causing all cases to fail

I am trying to create a validation rule that stops users from creating a case if they don't fill out a certain picklist field called "Order Type".  I only want this validation rule to apply to cases manually created by a user, and not any created by the "system" user, that is the creator of all incooming email2case cases.  I put together the rule below, thinking it would work just fine, but had pretty much the opposite effect.  Instead of skipping all of the cases created by the system user (005d0000001bgP5), it looked at all those cases and stopped them from being created, since they are auto-created by email2case and we don't have a defalut value for the "Order Type" field established, so that field was always blank and caused this error.  Does anyone know why the validation rule is not working as expected and looking at ALL my cases with this record type instead of just the cases NOT created by the user noted in the below rule?  Thanks in advance!!

And(CreatedById <> '005d0000001bgP5', RecordTypeId = '012d0000000P8Eu', ISPICKVAL(Order_Type__c,""))
 
Ravi Dutt SharmaRavi Dutt Sharma
Hey Renee,

Try below validation rule, let me know if it works.
 
IF(
CreatedById = '005d0000001bgP5',
FALSE,
	IF(
	AND(RecordTypeId = '012d0000000P8Eu',ISPICKVAL(Order_Type__c,"")),
	TRUE,
	FALSE)
)

 
Mahesh DMahesh D
Hi Renee,

CreatedById will be null when you are inserting the record, hence you can use the below validation rule.
 
And($User.Id <> '005d0000001bgP5', RecordTypeId = '012d0000000P8Eu', ISPICKVAL(Order_Type__c,""))

Here I am checking it with User Id so that it will be always have a value.

Along with it, I would recommend to not to hardcode the values as it will be tough to maintain it in other environments.

Please do let me know if it helps you.

Regards,
Mahesh
Renee Marie ProrokRenee Marie Prorok
Thanks Ravi, but this rule is preventing any email2case cases from being created (which are created by the user mentioned in the rule).  This is the issue I am facing now - my rule is somehow preventing cases to be created by the user in my validation rule, which is the assigned email2case user, so none of our cases are being created.

I am looking for the "Order Type" field to be required on all cases with the specified record type, except those created by the specific user, and I want the rule to be triggered when the associate first hits "Save" to create the case, not after creation.  Any ideas?