You need to sign in to do that
Don't have an account?
Sreenivas V
trigger to rollup opportunity amount on Account field where opportunity record type is "Revenue Type" Opportunity field: Opty_Amount_C Account field: Total_Opty_Amount_C
Hi,
I got this question in some interview, where I tried to solve but unsuccessful. Please help me out.
trigger to rollup opportunity amount on Account field where opportunity
record type is "Revenue Type"
Opportunity field: Opty_Amount_C
Account field: Total_Opty_Amount_C
I got this question in some interview, where I tried to solve but unsuccessful. Please help me out.
trigger to rollup opportunity amount on Account field where opportunity
record type is "Revenue Type"
Opportunity field: Opty_Amount_C
Account field: Total_Opty_Amount_C
Please refer below code
If this helps, please mark it as best answer.
All Answers
Please refer below code
If this helps, please mark it as best answer.
This is how you can roll up a field of Opportunity based on a Record Type.
Please Mark this as best answer if it answers your question.
I wanted a apex code for the above problem, indeed thanks for your suggestion.
trigger AmountTrigger on Opportunity (after update,after insert)
{
Set<id> accid= new Set<id>();
List<Account> ac1= new List<Account>();
for(Opportunity op3:Trigger.new)
{
accid.add(op3.AccountId);
}
List<Account> ac2=[select id,Amount__c,(select id,Amount from Opportunities where RecordTypeId='<recordtypeId>') from Account where ID =:accid];
for(account opn:ac2)
{
Double TotAmt=0.0;
for(Opportunity op4:opn.opportunities)
{
TotAmt+=op4.Amount;
}
opn.Amount__c=TotAmt;
ac1.add(opn);
}
Update ac1;
}
Do not forget to give the recordtypeId which I have highlighted with a bold letters. This will work.
Thanks for the code. even pradeep singh's code also works and covered all scenarios.
Great..Good luck for your job interviews..
Create a field on Account. field name would be Total Opportunity Amount(data type – Currency(16,2)). When an Opportunity is inserted/updated then the Total Opportunity Amount will be updated on associated Account from All Opportunities related to this account.
thanks in Advance