+ Start a Discussion
Zain ButtZain Butt 

Create Opportunity Amount field Trigger to Roll-up from Opportunity Products

I'm tasked with creating an Opportunity Amount field Trigger to Roll-Up from Opportunity Products. How would I go about creating this trigger to roll up from Opportunity Products? Sample code would be awesome!

Sincerely,
Junior Developer!
Best Answer chosen by Zain Butt
Tarun Khatri (TK)Tarun Khatri (TK)
Hello Zain,

Write a trigger on Opportunity Product (after insert, after update) which will count amount of all products associated with Opportunity record. Add the amount and update parent Opportunity record.

Get Opportunity Id from incoming Oppty Product. Extract all Oppty product associated with Opportunity using SOQL. In FOR LOOP, calculate Total Amount and Update Opty field with Total amount.

It will be a few lines of code. Try it yourself. This way you will learn more.

Best of Luck!!!

-Thanks,
TK

All Answers

Tarun Khatri (TK)Tarun Khatri (TK)
Hello Zain,

Write a trigger on Opportunity Product (after insert, after update) which will count amount of all products associated with Opportunity record. Add the amount and update parent Opportunity record.

Get Opportunity Id from incoming Oppty Product. Extract all Oppty product associated with Opportunity using SOQL. In FOR LOOP, calculate Total Amount and Update Opty field with Total amount.

It will be a few lines of code. Try it yourself. This way you will learn more.

Best of Luck!!!

-Thanks,
TK
This was selected as the best answer
Madhu SFDC PhoenixMadhu SFDC Phoenix
Hi Zain Butt,

It's a standard functionality provided by salesforce. Amount field on opportunity will be rolled up from opportunity products. if need any support please reach me.

Thanks
Madhu
+91-9940589878
Manju SeraiManju Serai
Hi Can you please guide me through steps. I am looking to create a rule where opportunity amount cannot be entered directly on opportunity page and it has to pickup only from products that are entered else the value remains 0