0

I am writing a validation rule to add a error message on case close page, if user trying to change the case status to resolved for the already resolved cases then it should through an error stating that you can not resolve the case that already resolved.  I have written the below logic : 

IF( 
AND 
( 
OR(
ISPICKVAL(PRIORVALUE(Status),'Resolved'),
ISPICKVAL(PRIORVALUE(Status),'Resolved - Redirected'),
ISPICKVAL(PRIORVALUE(Status),'Resolved – Duplicate/Invalid')
) , 
OR(
ISPICKVAL(Status,'Resolved'),
ISPICKVAL(Status,'Resolved - Redirected'),
ISPICKVAL(Status,'Resolved – Duplicate/Invalid')
)
),TRUE,FALSE 
)

But, when i am trying to close the case for the first time also system is throughing the below error:::

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger CaseEventActions caused an unexpected exception, contact your administrator: CaseEventActions: execution of AfterUpdate caused by: System.DmlException: Upsert failed. First exception on row 0 with id a0Dq0000008ulxMEAQ; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You cannot resolve the case that is already resolved. Please reopen the case to edit.:
[Status]: Class.StatusHistoryHelper.statusHistoryByStatus: line 94, column 1

1 Answer 1

0

Just to simplify, any time you have a formula that looks like this:

IF([SOMETHING HERE], TRUE, FALSE)

you can replace the whole thing with just

[SOMETHING HERE]

You don't need an IF() function to convert a Boolean value into another Boolean value.

If we make that simplifying change and add some indenting, the formula becomes a little cleaner to understand:

AND( 
    OR(
        ISPICKVAL(PRIORVALUE(Status),'Resolved'),
        ISPICKVAL(PRIORVALUE(Status),'Resolved - Redirected'),
        ISPICKVAL(PRIORVALUE(Status),'Resolved – Duplicate/Invalid')
    ) , 
    OR(
        ISPICKVAL(Status,'Resolved'),
        ISPICKVAL(Status,'Resolved - Redirected'),
        ISPICKVAL(Status,'Resolved – Duplicate/Invalid')
    )
)

The problem that's causing your trigger to fail is that the rule doesn't check if Status has actually changed. Any irrelevant update to the Case once it hits a Resolved status will cause the rule to fire, because in that situation both the prior value and current value of the field are that status value.

You need to add ISCHANGED(Status) check to avoid this issue.

1
  • Hi David, With this logic i can not display the error when user trying to close and save the page with same status (i.e, resolved), could it be possible to display the error in this scenario. Commented Mar 8, 2019 at 5:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .