+ Start a Discussion
cdolcdol 

Trigger that finds records by date, updates field

Hello,

 

I'm totally new to Apex Triggers, but I believe I have a good mental map of what needs to happen to overcome my 'issue'.

 

I have Opportunity (1-1 with Accounts for our org), Sequoia_Service_Level__c, and Accounting__c objects. I'd like to 'call' the trigger by way of a button, since I need to create all Accounting__c records before executing this logic.

 

I need to take the total count of Accounting__c records in the given month, and pro-rate an amount found on the Opportunity (called Revenue_Opportunity__c, which is a roll-up summary of the field "Total_Invoice_Amount__c" on the Current_Service_Level__c object).

 

For instance, if I had 3 Accounting__c records, with a Revenue_Opportunity__c of $10 from the related Opportunity object, each accounting object would be given the value 3.3333... Then, that 3.333 should be set to the field Accounting__c.Baseline_Service_Amount__c.

 

Accounting__c objects have a lookup relationship to Opportunities and Accounts, and all have a related Sequoia_Service_Level__c as well.

 

Is this pretty straightforward stuff? Or will this be quite difficult? I'm already finding invoices for the current month via a report (which is then PDF'd using CongaComposer), but I figured I could not take advantage of that with an Apex Trigger?

 

Any guidance is appriciated!

 

Charlie

 

imutsavimutsav
This should be straight forward as you need to create a Trigger on Opportunity after insert or after update. In the trigger query all the Accounting Objects which is attached to this Opportunity. and then do your calculation and update the field on your Accounting object and then update the accounting object list.

Thanks
Utsav