The total hours are rolled up to the Project object by default in the TimeTracker application.
For any other custom object, you can write trigger and roll up Approved or Total hours by following the instructions below
Firstly, we need to create the Custom Fields, Custom Trigger, and the related test class with at least 75% code coverage in the Sandbox. Then test the trigger in Sandbox, and push the trigger to the Production org. Because Salesforce does not allow you to write triggers directly in your Production org.
- Set up triggers in a sandbox to do the roll-ups
- Write test classes to get code coverage for the triggers
- Test out the triggers to make sure that the roll-ups in the sandbox
- Push the triggers to your production org.
Note: As an example, I am using Banking as a custom object in this article
In Sandbox Org,
- New Custom Field on Custom Object(Banking Object):
- Create two Custom Fields of Data type number in the Custom Object(Banking Object).
- Approved Hours (Sum of Hour's roll-up from the TT Details object where Status is Approved).
- Actual Hours (Sum of Hour's roll-up from the TT Details object of all Status).
- Create two Custom Fields of Data type number in the Custom Object(Banking Object).
- Create a Custom Trigger on TT Details Object:
- The Trigger will be initialed "After" the Record is (Update/Create/Deleted).
- Logic on Rollup hours:
- Get all the TT Details from the TT Details Object grouped by Banking and Status.
- Calculating the Hours for both Approved Hours and Actual Hours
- Summarize the hours for all the statuses.
- Summarize the hours where Status is equal to Approved.
- Update the Calculated hours(Approved Hours and Actual Hours) on the Banking object.
- Create a Test Class for the above trigger and it should cover at least 75% of Code Coverage.
- Create Inbound Change Set Package:
- Inbound Change Set should contain,
- New Custom Field
- New Custom Trigger
- Test Class
- Inbound Change Set should contain,
In Production Org,
- From Outbound Change Set
- Select the Package,
- Click on Validate Button and Check for the Validation Status.
- Click on Deploy Button will revalidation all the test scenarios and then deploys the Change Set.
- Select the Package,