You need to sign in to do that
Don't have an account?
Trigger to update the balance amount on a bill
Dear Folks,
I have been struggling with trying to write a trigger to update a balance on a bill when a payment is made on it. The progress I have made is below:
trigger UpdateBalanceOnPayment on Payment__c (after insert) { for (Payment__c payment : Trigger.new) { Bill__c bill = [SELECT Id, Balance__c FROM Bill__c WHERE Id = :payment.Bill__c.Id]; } }
For some reason the Force.com IDE says invalid foreign key relationship and does not synchronize with the server.
Each payment will have a master detail relationship with the associated bill when it is saved and I want to reduce the balance on the bill by the amount made by the payment after the payment is saved.
However I have not even got to that stage yet because it looks like I have made a mistake in the query. I would appreciate any pointers you can lend on this problem.
Many Thanks
nandac
Hi,
It is not a good practise to include a SOQL inside a trigger. Hope the below code helps
-ಸಮಿರ್
All Answers
Hi,
It is not a good practise to include a SOQL inside a trigger. Hope the below code helps
-ಸಮಿರ್
Thanks that works but I think you meant to have the if statement like this without the "!". Do let me know if I am wrong in this case but the trigger does what I envisaged now. :-)
updated the code. Thanks!