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
Jan AertgeertsJan Aertgeerts 

How to validate if a value is the same as a roll-up summary when a certain step in approval process is attempted

I have an approval process. When I reach a certain point in this process, I need to make sure certain fields (of the child object) are filled in. I have a roll-up summary of (invoice lines) amounts that should equal the total invoice amount that was filled in in the header information.
So basically: someone shouldn't be allowed to approve something when Total_invoice_lines__c  does not equal Final_Amount__c.

Can someone please advise?
Best Answer chosen by Jan Aertgeerts
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Jan Aertgeerts

 My suggestion is not to rely on roll-up summary fields, as salesforce in its documentation claims that it might take upto 30 minutes for a roll up to be caluculated due to several reasons. So i would recommend writting a trigger on the object to handle this., 
In eloaborate, follow the below steps:

-> Create a dummy checkbox/field in the object that the approval process is configured on.
-> In an approval step configuration you need the validation, do a field update approval action and check this box on
-> Write a before update trigger on same object and validate your criteria and throw an error if it doesnt match your criteria.
-> Since the approval process field update hits the trigger validation, it doesnt allow the user to perform that approval action by displaying the error you thrown from the trigger.

Hope this helps:

Thanks,
Balaji