-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateOrderTotal.txt
More file actions
22 lines (19 loc) · 850 Bytes
/
Copy pathUpdateOrderTotal.txt
File metadata and controls
22 lines (19 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
trigger UpdateOrderTotal on HandsMen_Order__c (before insert, before update) {
Set<Id> productIds = new Set<Id>();
for (HandsMen_Order__c order : Trigger.new) {
if (order.HandsMen_Product__c != null) {
productIds.add(order.HandsMen_Product__c);
}
}
Map<Id, HandsMen_Product__c> productMap = new Map<Id, HandsMen_Product__c>(
[SELECT Id, Price__c FROM HandsMen_Product__c WHERE Id IN :productIds]
);
for (HandsMen_Order__c order : Trigger.new) {
if (order.HandsMen_Product__c != null && productMap.containsKey(order.HandsMen_Product__c)) {
HandsMen_Product__c product = productMap.get(order.HandsMen_Product__c);
if (order.Quantity__c != null) {
order.Total_Amount__c = order.Quantity__c * product.Price__c;
}
}
}
}