antonpug
antonpug

Reputation: 14286

How can I filter data in an Apex Grid to show certain things for certain user groups?

I have an ADMIN group and a USER group. My data looks something like this raw:

ID ---------- NAME --------- SECTOR
0001          John           A
0002          John           H
0024          John           A
0011          John           H
0045          John           A

The ADMIN group should only be able to see A, and the USER group should only be able to see H. How can I customize the gridview in Apex to filter it based on authorization/groups?

Upvotes: 1

Views: 1444

Answers (1)

Tony Andrews
Tony Andrews

Reputation: 132580

Since you are using APEX built-in groups, there is a function APEX_UTIL.GET_GROUPS_USER_BELONGS_TO that can help you here. It returns a comma-separated list of the groups the user belongs to. So you could use it something like this:

select id, name, sector
from employees
where ((','||apex_util.get_groups_user_belongs_to(:app_user)||',' like '%,ADMIN,%'
      and sector = 'A')
or (','||apex_util.get_groups_user_belongs_to(:app_user)||',' like '%,USER,%'
      and sector = 'H'))

Upvotes: 1

Related Questions