Hi Eyup, try with below code.
If this helps, please mark it as best answer.thanks!!trigger AvailableQuantityUpdate on Purchase_Orders__c (After insert, after update) {
map<id,string> accdesmap = new map<id,string>();
set<id> accids = new set<id>();
If ((trigger.Isupdate ||trigger.Isinsert ) && trigger.Isafter){
for(Purchase_Orders__c acc: trigger.new){
If(acc.Inventory__c != Null){
accdesmap.put(acc.Inventory__c,acc.Quantity_Received__c);
accids.add(acc.Inventory__c);
}
}
}
List<Inventory__c> AvailableQuantityUpdate = new List<Inventory__c>();
List<Inventory__c> intlist = [select id,Available_Quantity__c from Inventory__c where id =:accids];
for(Purchase_Orders__c acc:trigger.new){
for(Inventory__c opp:intlist){
if(accdesmap.containsKey(opp.id)) {
opp.Available_Quantity__c= accdesmap.get(opp.id);
AvailableQuantityUpdate.add(opp);
}
}
// }
If(opptoUpdate.size()>0) {
update AvailableQuantityUpdate;
}
}
1 Antwort