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

Update Master record with child value
Hi All,
Following is a code i have written to update value of a field (Test__c) on master object "Invoice" with value from child object "Mail" field (Signature__c)
/* Assumption - only one child per parent record */
------------------------------------------------ Code------------------------------------------------------
trigger InventoryItemRollup on Mail__c (after delete, after insert, after update) {
Set<id> shipmentIds = new Set<id>();
List<Mail__c> ma = new List<Mail__c>();
List<Invoice__c> shipmentsToUpdate = new List<Invoice__c>();
List<string> s = new List<string>();
for (Mail__c m:ma)
{
s.add(m.Invoice__c);
for(string s1:s)
{
for (Mail__c item : Trigger.new)
shipmentIds.add(item.Invoice__c);
if (Trigger.isUpdate || Trigger.isDelete) {
for (Mail__c item : Trigger.old)
shipmentIds.add(item.Invoice__c);
}
Map<id,Invoice__c> shipmentMap = new Map<id,Invoice__c>([select id, Test__c from Invoice__c where id=:s1]);
for (Invoice__c ship : [select Id,Test__c,(select Id,Signature__c from Mails__r)from Invoice__c where Invoice__c =:s1]) {
shipmentMap.get(ship.Id).Test__c = shipmentMap.get(ship.Id).Mails__r.Signature__c;
shipmentsToUpdate.add(shipmentMap.get(ship.Invoice__c));
}
update shipmentsToUpdate;
}
}
}
---------------------------------------------------- Code -------------------------------------------------------------------
Above not working.
The error must be very basic.
Please pardon my naivety.
Thanks in advance,
Anidev
Ref: Code by Jeff Douglas on roll-ups
I hope this would work.
you have nothing in ma, and so never enters the loop.