Print this page

Preventing users from deleting closed Opportunities

Knowledge Article Number 000003313

We need to prevent Users from deleting closed Opportunity records. They should still be able to delete open Opportunity records.


You can achieve this result by setting up a Roll-Up Summary field on Accounts to sum the number of closed Opportunities. For this example we will call this field 'Num Closed Opps'. See "Defining Roll-Up Summaries" for additional information.

Next, create a Validation Rule on Accounts to prevent decreases in the value of 'Num Closed Opps'. This rule would use syntax like:

$Profile.Name <> "System Administrator" &&
Num_Closed_Opps__c < PRIORVALUE ( Num_Closed_Opps__c )

This syntax will cause an error when any user whose profile is not "System Administrator" decreases the value of the 'Num Closed Opps' field. Thus, when a user tries to delete a closed Opportunity, the roll-up field on the Account would be decreased, which triggers the validation error and prevents the deletion.

See "Defining Validation Rules" for additional information.

promote demote