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
MattyRayMattyRay 

Opening/Close child record(s) on Opportunity Save.

Hello,

 

So I'm new to apex...

We have a formula field on the opportunity called "department", which is formulated from another lookup relationship to an object called "Employee".  Obviously, The department value changes as the lookup "Employee" value is changed. 

 

 

Here's the issue.  We have a child object (related to the opportunity) called "Financial Data".  For several reasons, I need to open/close the child "financial data" record everytime the opportunity is saved.

 

Does anyone know of a quick trigger to do this?  Test Coverage class would also be appreciated.

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
MattyRayMattyRay

OK, I was able to finish this and it works great.

 

trigger UpdateFinancials on Opportunity (after update) {

For(Opportunity Deal: Trigger.New){
List<Financial_Data__c> Financials =[select Id ,Deal__R.Id, DepartmentText__c from Financial_Data__c where Deal__c=:Deal.Id];
        update Financials;
}
}