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
sudhakara reddy 13sudhakara reddy 13 

Requriment

I have question, i have custom object called broker with field called  Funding CFY (Currency field) and broker object have look up relationship with contact. so take all the opportunities of the cintact of the broker record the created date time of the opportunity should be in the current financial year(1/07/2017 to 30/06/2018) & opportunity stage= closed won calculate the sum of the "amount" field of all such opportunities & assign the sum to the field funding CFY in broker object.

Could you please help me on this bit urgent..

Thanks advance
Rishabh Agrawal 18Rishabh Agrawal 18
trigger brokerTrigger on Broker__c(before insert, before Update){

Integer totalAmount = 0;
           for(OpportunityContactRole ocr: SELECT Id, Opportunity.Amount FROM 
                             OpportunityContactRole where ContactId = trigger.new[0].ContactID AND                                   Opportunity.stage= 'Closed Won'){
           totalAmount += ocr.Opportunity.Amount;
}
trigger.new.put('Funding_CFY__c', totalAmount );
}
Try this code it's not bulkified you can do it as per your requirement and update it if you want any changes. Basics of this trigger is--
1.) You have to write trigger on Broker Object.
2.) Query Opportunity Contact Role object by putting where condition.
3.) Calculate the amount and update it on Broker record.(If we are assigning before insert or update you don't have to do a DML.)

Let me know if it works and Please mark as best answer.