You need to sign in to do that
Don't have an account?
Lavanya Ponniah 3
How to do the below trigger?
I need assistance with the below trigger, the line which i bold and underlined.When i insert bulk record using dataloader.io for all records v.Pending_Hardware_Installations_Order__c = ordr.Left_Hardware__c; is to reflect the updated ordr.Left_Hardware__c ,but for all records its not reflecting the updated ordr.Left_Hardware__c to the v.Pending_Hardware_Installations_Order__c .
trigger InstalledHardware on Vehicle_Details__c (before insert)
{
Set<Id> setOrderIds = new Set<Id>();
Map<Id,Order> mapIdWithOrder = new Map<Id,Order>();
for(Vehicle_Details__c V:trigger.new){
if(v.Order__c != null){
setOrderIds.add(v.Order__c);
}
}
if(!setOrderIds.isEmpty()){
for(Order ordr :[select Order_Number__c,Finished_HardWare__c,Left_Hardware__c,Total_Hardware_Type_Ordered_Products__c from Order where id IN :setOrderIds]){
mapIdWithOrder.put(ordr.Id,ordr);
}
}
for(Vehicle_Details__c V:trigger.new){
if(v.Order__c != null && mapIdWithOrder != null && mapIdWithOrder.get(v.Order__c) != null){
Order ordr = mapIdWithOrder.get(v.Order__c);
v.Pending_Hardware_Installations_Order__c = ordr.Left_Hardware__c;
v.Total_Hardware_Quantity_for_Order__c = ordr.Total_Hardware_Type_Ordered_Products__c;
ordr.Finished_HardWare__c = ordr.Finished_HardWare__c + V.Total_Hardware_Installed__c;
mapIdWithOrder.put(v.Order__c,ordr)
}
}
if(mapIdWithOrder.values().size() > 0)
{
update mapIdWithOrder.values();
}
}
trigger InstalledHardware on Vehicle_Details__c (before insert)
{
Set<Id> setOrderIds = new Set<Id>();
Map<Id,Order> mapIdWithOrder = new Map<Id,Order>();
for(Vehicle_Details__c V:trigger.new){
if(v.Order__c != null){
setOrderIds.add(v.Order__c);
}
}
if(!setOrderIds.isEmpty()){
for(Order ordr :[select Order_Number__c,Finished_HardWare__c,Left_Hardware__c,Total_Hardware_Type_Ordered_Products__c from Order where id IN :setOrderIds]){
mapIdWithOrder.put(ordr.Id,ordr);
}
}
for(Vehicle_Details__c V:trigger.new){
if(v.Order__c != null && mapIdWithOrder != null && mapIdWithOrder.get(v.Order__c) != null){
Order ordr = mapIdWithOrder.get(v.Order__c);
v.Pending_Hardware_Installations_Order__c = ordr.Left_Hardware__c;
v.Total_Hardware_Quantity_for_Order__c = ordr.Total_Hardware_Type_Ordered_Products__c;
ordr.Finished_HardWare__c = ordr.Finished_HardWare__c + V.Total_Hardware_Installed__c;
mapIdWithOrder.put(v.Order__c,ordr)
}
}
if(mapIdWithOrder.values().size() > 0)
{
update mapIdWithOrder.values();
}
}
In the above trigger you are only updating Order object. Try updating Vehicle_Details__c object.
Thanks
Kumar
If this answers your question, please mark this as Best Answer.
Vehicle_Details__c, during insert value should be automatically updated.
Also it is incorrect to update related object in insert trigger, related objects should be updated in after trigger
I cannot see any problem with your trigger. I would say that you just don't have the information that you want to reflect it into the vehicle object. I would follow Vidya D suggestion to ensure that the data exists. However do not forget to remove your System.debug lines as it count against Salesforce execution limits.
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.