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
Ben RosenbergBen Rosenberg 

Calculate total cost based on matching PO numbers

Hi,

I have an object with custom fields "po_number" and "repair_cost" and would like to add a third field "total cost" calculated on the SUM of the repair_cost field for any records that have matching po_number fields.

Could I do some sort of read of the po_number field and then a loop? (I know this is not the proper syntax, I hope I'm getting the idea across though) i.e. FOR(VALUE in po_number) do SUM(repair_cost)

or could I read in the value of the po_number field on the current record, then calculate to total cost based on any matching values on other records?

 
Best Answer chosen by Ben Rosenberg
Navandeep_Kaur23Navandeep_Kaur23
Hi Ben,

It seems you wat to create a roll up summary field within same object to calculate the sum based on matching po_number but currently salesforce doesn't support that and there is one similar idea posted https://success.salesforce.com/ideaView?id=08730000000BrqGAAS to have this feature based on Hierarchy relationship.
But in your case its better you should create another object having Master relationship to this object and  calculate total sum using roll up summary or usinf simple trigger if you create lookup relation.
Let me know if that helps or provide some more detail on your issue s might help you with some better solution

Thanks

All Answers

Navandeep_Kaur23Navandeep_Kaur23
Hi Ben,

It seems you wat to create a roll up summary field within same object to calculate the sum based on matching po_number but currently salesforce doesn't support that and there is one similar idea posted https://success.salesforce.com/ideaView?id=08730000000BrqGAAS to have this feature based on Hierarchy relationship.
But in your case its better you should create another object having Master relationship to this object and  calculate total sum using roll up summary or usinf simple trigger if you create lookup relation.
Let me know if that helps or provide some more detail on your issue s might help you with some better solution

Thanks
This was selected as the best answer
Navandeep_Kaur23Navandeep_Kaur23
You can also refer below link for a similar scenario but it also require to have MD relationship.
https://success.salesforce.com/answers?id=90630000000CnmlAAC
Ben RosenbergBen Rosenberg
Yes, it looks like what I am trying to do is create a rollup within the same object. Interesting that I would need a master relationship. Thank you for the links, I will look into them and see if they provide insight in how I can accomplish what I'm trying to do. Thank you!