+ Start a Discussion
Surendra123Surendra123 

Trigger Error on product object with data loader

ProductFieldUpdate: execution of BeforeUpdate

caused by: System.TypeException: Invalid decimal: STEEL 520X4.6MM

Trigger.ProductFieldUpdate: line 18, column 1

 

Here is my trigger code

 trigger ProductFieldUpdate on Product2 (Before insert, before update){
    for(Product2 p : trigger.new){
        if(p.Ampics_PL__c != null && p.Ampics_PL__c == 'UTILUX') {
        if(p.description.lastIndexOf('/') != -1) {
        Integer lastIndx = p.description.lastIndexOf('/');
         p.Pieces_in_Pack__c  = Decimal.valueOf(p.description.subString(lastIndx + 1));
         }
        else {
        p.Pieces_in_Pack__c = 1;
         
        
             }
           }
        }
        }

Deepa.B.AnkaliDeepa.B.Ankali
@Surendra123,

Error is at this line,
p.Pieces_in_Pack__c = Decimal.valueOf(p.description.subString(lastIndx + 1));
Since 'STEEL 520X4.6MM' isnt a decimal. You can parse for the numeric in this and assign.
Surendra123Surendra123
@Deepa

Thanks but my trigger is working fine when i tried to update the data using dataloader i was getting this error
ProductFieldUpdate: execution of BeforeUpdate

caused by: System.TypeException: Invalid integer: STEEL 520X4.6MM

Trigger.ProductFieldUpdate: line 18, column 1

Code:
trigger ProductFieldUpdate on Product2 (Before insert, before update){
for(Product2 p : trigger.new){
if(p.Ampics_PL__c != null && p.Ampics_PL__c == 'UTILUX') {
if(p.description.lastIndexOf('/') != -1) {
Integer lastIndx = p.description.lastIndexOf('/');
p.Pieces_in_Pack__c = Decimal.valueOf(p.description.subString(lastIndx + 1));
}
else {
p.Pieces_in_Pack__c = 1;


}
}
}
}