I have an invoice payment child object (gii__ARInvoicePayment__c) related to the parent invoice object (gii__OrderInvoice__c).
I created a trigger on the child, that updates the payment date on the invoice when the full payment is posted.
There is a status formula field on the parent that updates to "PAID" when the balance on the invoice is equal to zero. The balance is determined by a currency field called Invoice Total - the roll up sum of the Payment field on the child records (gii__ARInvoicePayment__c). It doesn't get updated to "PAID" until after the gii__ARInvoicePayment__c record is saved so I think that is causing my trigger to not update the payment date field on the parent object. Does anyone have any suggestions on how I can go about this? Thanks!
trigger Update_Payment_Date on gii__ARInvoicePayment__c (after insert, after update) {
List<gii__OrderInvoice__c>lstInvoiceToUpdate = new List<gii__OrderInvoice__c>();
Map<Id,gii__OrderInvoice__c>invoiceMP;
for(gii__ARInvoicePayment__c pmt:trigger.new)
{
if (pmt.gii__PaymentDate__c != null && pmt.Invoice_Status__c == 'PAID')
{
lstInvoiceToUpdate.add(new gii__OrderInvoice__c(Id = pmt.gii__Invoice__c, Paid_Date__c = pmt.gii__PaymentDate__c, gii__PaymentDate__c = pmt.gii__PaymentDate__c));
}
}
update lstInvoiceToUpdate;
}
gii__OrderInvoice__c
, Child =gii__ARInvoicePayment__c
). It's also not clear what your problem is. What does "it's not working" mean? How is it supposed to work, and how is that different from what you're observing? Are you getting any error messages? I think we'll need this information, and more information about the flow of data/events, to be able to provide any suggestions. You should edit your question to include these details.Invoice_Status__c
is a formula field, but it'd be good for you to explicitly confirm that. Given that information, answering the following questions should help get you an answer: How does an ARInvoicePayment end up with a zero balance (Does a human manually do it? A workflow rule? Process Builder? Apex? something else?)? Who or what sets thegii__Payment_Date__c
? Can there be multiplegii_ARInvoicePayment__c
pergii__OrderInvoice__c
or is there some business rule that mandates this is a 1:1?