-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCannotChangeAmountAtClosedWonHelper.java
33 lines (32 loc) · 1.72 KB
/
CannotChangeAmountAtClosedWonHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* @description : Helper Class for Handling Restrictions on Amount and Discount Changes at Closed Won Stage.
* @author : Rajnish
* @group : Service
* @last modified on : 23/12/23
* @last modified by : Rajnish
* Modifications Log
* Ver Date Author Modification
* 1.0 23/12/23 Rajnish Initial Version
**/
public class CannotChangeAmountAtClosedWonHelper {
/**
* @description: Handles restrictions on Amount and Discount changes when the StageName is set to "Closed Won."
* @param newOppRecords: List of new Opportunity records to be processed.
* @param oldOppRecords: Map of old Opportunity records (Id to Opportunity) for comparison.
*/
public static void handleBeforeUpdate(List<Opportunity> newOppRecords, Map<Id, Opportunity> oldOppRecords) {
for (Opportunity newRecord : newOppRecords) {
Opportunity oldRecord = oldOppRecords.get(newRecord.Id);
// Check if both old and new stages are "Closed Won" and Amount is changing
if (oldRecord.StageName == 'Closed Won' && newRecord.StageName == 'Closed Won' &&
oldRecord.Amount != newRecord.Amount) {
newRecord.Amount.addError('Amount cannot be changed once the Stage is set to Closed Won.');
}
// Check if both old and new stages are "Closed Won" and Discount is changing
if (oldRecord.StageName == 'Closed Won' && newRecord.StageName == 'Closed Won' &&
oldRecord.Discount__c != newRecord.Discount__c) {
newRecord.Discount__c.addError('Discount cannot be changed once the Stage is set to Closed Won.');
}
}
}
}