I have one major problem in domain of already relatively "large" code for implementation of assigning custom roles to users. By "large" I mean it would be a problem to reproduce example on apex.com with all the objects creation, triggers, tables, transactions, page code, etc...
Basically I have a Shuttle where I move users from left to right to assign them a specific role. Vice versa to take roles from them.
What I need is is knowledge of how to get/refer to values which are on the left side of shuttle(unselected users), and the right side(selected users). Values of users are their IDs of course.
But the point is that before I submit page I need values of users from the left side of shuttle so that I can use DELETE FROM table of roles. In the most shortest way possible by pseudo-code:
DELETE FROM user_role
WHERE user NOT IN (right side of shuttle)
or also possible:
DELETE FROM user_role
WHERE user IN (left side of shuttle)
There is nothing significantly specific to my case, I would just need a way to be able to catch values from left and right side separately. I might need other manipulations of both sides separately in different transactions, so I should be able to refer to them.
I searched on "how to get right values of shuttle item" for APEX, but no search results provided satisfying answer.
To give another example - I need to somehow track the last three past roles that user had. I was very close to a solution and even thought it worked, but behaviour was incorrect. As soon as I unselect user from role (move him to the left side of shuttle), and submit page, I need to insert timestamp value into separate table (user_roles_history) to signify end date and be able to get latest 3 roles user that had. But this is not going to work correctly if I can't get the exact shuttle value of user which ended up in left side of shuttle before submit. but this is also not going to work when I think about it, because it will insert end_date and timestamp for every user on the left side of shuttle after I submit regardless if it was moved there just now. So one option left is trigger. As soon as user is deleted from user_role table, trigger writes end time to the table with user id and role id. And as you can see, this assumes that when page is submit, delete from user_role table must be performed only upon users existing in this table who are on the left side of shuttle.
So that's my question, how to access values on both sides of shuttle separately?