+ Start a Discussion
Elgun Aliyev 2Elgun Aliyev 2 

Validation based on multiple records' values

Hi everyone,

We have multiple records (same record type) and User input percentage field. We need to make sure sum of that field is 100%. Is there any way of validating it in Visualforce page or so?

For example,

Record A    50%
Record B    25%
Record C    based on the inputs above percent for this record must be 25%


Kind regards,

Elgun
Best Answer chosen by Elgun Aliyev 2
willardwillard
Absolutely.

I'm sure you have a controller that has a list of records that you want to display on the page?  I also assume this percentage field is bound to the sobject.  There are many ways to do this.

The simplest one would be to have a apex:commandButton on the page that will validate to ensure that all percentages add up to 100%.  You can just do this straight on your save button and just have a validate method called within your save code.

All Answers

willardwillard
Absolutely.

I'm sure you have a controller that has a list of records that you want to display on the page?  I also assume this percentage field is bound to the sobject.  There are many ways to do this.

The simplest one would be to have a apex:commandButton on the page that will validate to ensure that all percentages add up to 100%.  You can just do this straight on your save button and just have a validate method called within your save code.
This was selected as the best answer
Elgun Aliyev 2Elgun Aliyev 2
Thanks for the information Willard