function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kishore kumar 20kishore 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
Sunil PalSunil Pal
Hi kishore kumar 20,

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
kishore kumar 20kishore kumar 20
Map is required as i am trying to update quantity with prod name.. Can you please share the code...? how to resolve the issue?