You need to sign in to do that
Don't have an account?
kishore kumar 20
Trigger error
trigger productsQtyUpdate on IS__c (after insert) {
Map<ID, PI__c> pqtyMap = new Map<ID,PI__c>();
Set<string> pid = new Set<string>();
Decimal soldQty;
for(IS__c pSoldqtyId:trigger.new){
soldQty = pSoldqtyId.Sold__c;
pid.add(pSoldqtyId.Name);
}
pqtyMap = new Map<ID,PI__c>([SELECT id,Quantity__c FROM PI__c where id In :pid]);
for(IS__c pSoldqty:trigger.new){
PI__c pqty = pqtyMap.get(pSoldqty.Name);
pqty.Quantity__c = pqty.Quantity__c - soldQty ;
}
update pqtyMap.values();
}
For the above trigger, i get the error while saving trigger.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger productsQtyUpdate caused an unexpected exception, contact your administrator: productsQtyUpdate: execution of AfterInsert caused by: System.StringException: Invalid id: 1: External entry point
Map<ID, PI__c> pqtyMap = new Map<ID,PI__c>();
Set<string> pid = new Set<string>();
Decimal soldQty;
for(IS__c pSoldqtyId:trigger.new){
soldQty = pSoldqtyId.Sold__c;
pid.add(pSoldqtyId.Name);
}
pqtyMap = new Map<ID,PI__c>([SELECT id,Quantity__c FROM PI__c where id In :pid]);
for(IS__c pSoldqty:trigger.new){
PI__c pqty = pqtyMap.get(pSoldqty.Name);
pqty.Quantity__c = pqty.Quantity__c - soldQty ;
}
update pqtyMap.values();
}
For the above trigger, i get the error while saving trigger.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger productsQtyUpdate caused an unexpected exception, contact your administrator: productsQtyUpdate: execution of AfterInsert caused by: System.StringException: Invalid id: 1: External entry point
I believe error is due to the "pqtyMap = new Map<ID,PI__c>([SELECT id,Quantity__c FROM PI__c where id In :pid]);" this line because you are storing the Name in Set of string and youare checking with Id. Please take a type of Set<id> and try may be it will resolve your issue.
Thanks
Sunil