Apex trigger to sum up (Count) amount from all the related Opportunity and set in custom field.
Handler class:
public class CustomRollUp {
public static void docount()
{
list<Opportunity> setopportunity = [ select Id, Name, Amount from Opportunity where
StageName = 'Closed Won' and RecordTypeId = '0127F00000166iGQAQ' ];
Double j = 0;
for( Opportunity op : setopportunity)
{
j += op.Amount;
}
list<Fund__c> updaterecord = new list<Fund__c>();
for (Fund__c f1 : [ select id from Fund__c ] )
{
f1.Total_opportunity_amount__c = j;
updaterecord.add(f1);
}
update updaterecord;
}
}
Trigger:
trigger CustomRollUp on Opportunity ( after insert , after update, after delete , after undelete) {
CustomRollUp.docount();
}
public class CustomRollUp {
public static void docount()
{
list<Opportunity> setopportunity = [ select Id, Name, Amount from Opportunity where
StageName = 'Closed Won' and RecordTypeId = '0127F00000166iGQAQ' ];
Double j = 0;
for( Opportunity op : setopportunity)
{
j += op.Amount;
}
list<Fund__c> updaterecord = new list<Fund__c>();
for (Fund__c f1 : [ select id from Fund__c ] )
{
f1.Total_opportunity_amount__c = j;
updaterecord.add(f1);
}
update updaterecord;
}
}
Trigger:
trigger CustomRollUp on Opportunity ( after insert , after update, after delete , after undelete) {
CustomRollUp.docount();
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment