function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tzemach Aronow 1Tzemach Aronow 1 

Trigger to populate a md relationship based on filter

When creating a line item, i have 3 Relationship fields.
1) Member lookup
2) Line item MD relationship (to the type of line item im creating.) (Donation to the donation fund its related to)
3) MD relation to an invoice.

1)Any donation a user enters should be added to a member. 2) It should be added to the donation fund. 3) it should be added to the members invoice.
If theres an Invoice with the selected members name and a statusof OPEN it should be added to that invoice, if not a invoice with that name should be created.

Either some help with the criteria i gave, or any better suggestions would be greatly appreciated.
TY 

I never wrote any apex code so any help you give me, please make it very detailed so I can follow along.
TY

KevinPKevinP
This is a great article on writing apex that will insert multiple object rows that are related to one another. Commonly called Cascading inserts.

https://developer.salesforce.com/blogs/engineering/2012/02/cascade-insert-with-external-id-fields.html