• kishore kumar 20
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
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
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