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

validation on status use

I'm trying to limit the usage of our pending statuses to only internal users.  I have added some code for validation on several statuses and added these in instead of 100s of validation rules.  
This is just a snippet.
//If the Status = Pending - NPI, fill in Product Category, Product Version and Defect Risk
                   if((objCase.CW_Current_User_s_Profile__c == 'CW Dealer Portal User' || objCase.CW_Current_User_s_Profile__c == 'CW Customer Portal Super User') && objCase.Status == 'Pending - NPI')
                       objCase.Status.addError('This status is restricted to Caterpillar. Choose another status.');
                   if(objCase.Status == 'Pending - NPI' && (string.isblank(objCase.Product_Category__c) || string.isblank(objCase.Product_Version__c) || string.isblank(objCase.NPI_Risk__c)))
                       objCase.addError('Fill in the Product Category, Product Version and Defect Risk for this case.');
                   }    }
The goal is to no allow Save if the customer or dealer user choose these statuses.  This works fine.  BUT if a case is already in one of these statuses and the customer or dealer go to edit the case, the validation rule also throws an error.  Without creating a new Support Process to weed out these statuses (tried that and it did not have favorable outcomes when it came to page layouts), how can I allows customer and dealer users to edit a case with this status, but not allow them to pick it from the Status list and Save. 

Andrew GAndrew G
This stack exchange post has some ideas that should give you a few options:

ISCHANGED or alternative in Apex Class - Salesforce Stack Exchange (