You need to sign in to do that
Don't have an account?

error while update the parent record
I am getting below error while update the value in parent record from the child reocrds collection
Apex trigger Totalquanityleft caused an unexpected exception, contact your administrator: Totalquanityleft: execution of AfterUpdate caused by: System.TypeException: Invalid id value for this SObject type: a0i0E0000000YDuQAM: Trigger.Totalquanityleft: line 31, column 1
My apologies am not so good in cdoing
sample lot is parent object, sample tarnsaction is child , quantiyty left is parent obecjt field, total quantity is child object field
Apex trigger Totalquanityleft caused an unexpected exception, contact your administrator: Totalquanityleft: execution of AfterUpdate caused by: System.TypeException: Invalid id value for this SObject type: a0i0E0000000YDuQAM: Trigger.Totalquanityleft: line 31, column 1
My apologies am not so good in cdoing
sample lot is parent object, sample tarnsaction is child , quantiyty left is parent obecjt field, total quantity is child object field
trigger Totalquanityleft on Sample_Transaction__c( after insert, after update,after delete,after undelete) { Set<Id> transactionIdSet=new Set<Id>(); List<Sample_Lot__c> ordListToUpdate=new List<Sample_Lot__c>(); if(Trigger.isInsert || Trigger.isUndelete){ for(Sample_Transaction__c qnty: Trigger.new){ if(qnty.id != null){ transactionIdSet.add(qnty.Id); } } } if(Trigger.isUpdate){ for(Sample_Transaction__c qnty: Trigger.new){ if(qnty.id != null && qnty.Transaction_Quantity__c != trigger.oldMap.get(qnty.Id).Transaction_Quantity__c){ transactionIdSet.add(qnty.Id); } } } If(Trigger.isDelete){ for(Sample_Transaction__c qnty : Trigger.old){ if(qnty.Id != null){ transactionIdSet.add(qnty.Id); } } } if(!transactionIdSet.isEmpty()){ for(AggregateResult res : [SELECT id,sum(Transaction_Quantity__c)can FROM Sample_Transaction__c WHERE id IN :transactionIdSet GROUP BY id]) { ordListToUpdate.add(new Sample_Lot__c (Id=(Id)res.get('Sample_Lot__c.id'),Quantity_Left__c=(Double)res.get('can'))); //ordListToUpdate.add(new Order(Id=(Id)res.get('OrderId'),Total_Pieces1__c=(Double)res.get('can'))); } } if(!ordListToUpdate.isEmpty()){ try{ update ordListToUpdate; }catch(DmlException de){ System.debug(de); } } }
On line 7, you are putting a record Id. You need to put the lookup field value there though.
If Sample_Lot__c is parent and Sample_Transaction__c child then find out the name of lookup field. ( e.g., Sample_Lot__c ) and change the code in line 7 and on 23 as following, Or use the trigger below,