Validation on aggregated child records

  • 1
  • Question
  • Updated 5 years ago
  • Answered
I have a parent record with Master-Detail child records that have a percentage field.  In my Skuid editor, I have the parent record up top and a table with the child records below it.  I'm need to create a rule where the child record(s) must exist and always sum to 100% when a Boolean field in the parent record is checked.  I've been trying to do this with SF validation rules, but I'm getting nowhere.  Is there some way I can do this on the client side with Skuid, or am I missing something on the validation rules side?

The SF parent validation rule I tried looks something like this if it helps:

IF(  AND(
NOT(ISNEW())
, Require100percent__c = TRUE
, SumOComponents__c <> 1.0
)
, TRUE, FALSE)

Thanks for the help.  Skuid is looking awesome still.
Photo of Tom W

Tom W

  • 142 Points 100 badge 2x thumb

Posted 5 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
This problem does sound best handedl with field validation on the salesforce side.  So you are on the right track.  But you might also explore some client side validation that Zach suggested a few weeks ago.  The scenario is a little different, but I think you could use concepts to work toward your solution.  Here is the link:   https://community.skuidify.com/skuid/topics/magic_real_time_error_warning_rendering_using_javascript...

(You will have to ignore my snide product development comment)
Photo of Tom W

Tom W

  • 142 Points 100 badge 2x thumb
Thanks for the direction.  Still working through this, but there is no rush.  Looks like when I add delete detail items, those aren't processed in the same transaction, so standard SF validation doesn't work in my case (ie, deletes, updates, and inserts are processed separately).  For instance, if I had 2 records with a 50/50 split and deleted one and changed one to 100%, validation would fail the transaction, whereas if i changed it to 80/20, it would work.  Makes sense to me at least... I'm new to SF though.

Long story short, it looks like client side is the way to go.  Need to learn some more Skuid API and javascript to make this happen I'm thinking.
Photo of Tom W

Tom W

  • 142 Points 100 badge 2x thumb
Alright, I think I have it figured out.  I'd like to use the problem indicator that Skuid has in place (red bar at the top).  Couldn't find any documentation, is there a simple way to submit issues to it?

for(var total = 0, i=0, len=skuid.model.map().IndexComponent.data.length;i<len;i++){        total +=Number(skuid.model.map().IndexComponent.data[i].Percentage__c);}
if(total===100)
{
    skuid.model.save([skuid.model.map().Index,skuid.model.map().IndexComponent])
}
else
{
alert('Index Components Must equal 100%')
}


Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Hi Tom, yes there is a way to add Messages to some of the core Skuid Components, for instance Page Titles, Field Editors, or Tables.

If you give one of these Components a Unique Id, then you can pass messages to its underlying skuid.ui.Editor like this:

var pageTitle = skuid.$('#MyPageTitle') // or whatever Unique Id you give it
var editor = pageTitle.data('object');
editor.handleMessages([
    { message: 'Index components must equal 100%', severity: 'ERROR' }
]);

If you change severity to WARNING, the message will be Yellow, or if you leave severity out entirely, the message will be Blue.

This is documented in this tutorial under skuid.ui.Editor, scroll down to the "handleMessages" method:

skuid.ui Object