I am in the early stages of learning Apex and trying to write some code for a particular scenario. I have two custom objects called Outstanding and Transaction that are both children of an Account. I want to write a trigger that updates the end date of the Outstanding record that has a start date >= the start date on the Transaction and an end date < the end date on the Transaction. I want the end date on the correct Outstanding record to change to the end date on the Transaction.
Example:
Transaction: Start_Date__c (is changed to)= 1/2/2019 End_Date__c=1/31/2020
Outstanding Records:
- Start_Date__c 1/4/2018 End_Date__c 1/4/2019
- Start_Date__c 1/4/2019 End_Date__c 1/4/2020
- Start_Date__c 1/4/2020 End_Date__c 1/4/2021
When the Transaction's start date is changed to 1/2/2019, I want the trigger to find the relevant Outstanding record 2 and update the end date to 12/31/2019.
Hopefully, that makes sense. If it doesn't, please let me know and I'll try to explain it again. Any help would be appreciated. Thanks.