0

Hello I have an apex:commandButton with action and if statement for rendering it.

rendered="{!IF(theCase.Status == '7', true, false)}

I somehow need to add to the rendered a statement, which will only allow it to appear for Queue with api names team_CT and team_ESK.

Thanks for any advice.

  • can you provide more details. do you have to check if running user is a member of team_CT or team_ESK queues and only if so display this section ? – Oleksandr Berehovskyi Sep 24 '18 at 11:01
  • yes exactly, user must be member of one of these queues – David Sep 24 '18 at 11:05
3

first, expression {!IF(theCase.Status == '7', true, false)} equals to {!theCase.Status == '7'}


to add some logic to rendering condition, you can use AND, OR, NOT.. logical functions.


if you are using custom controller - simply check if current user is a member of mentioned queue and set property hasAccessBasedOnQueue to true

e.g.

Controller:

public class with sharing CustController {
    public Boolean hasAccessBasedOnQueue {get; set;}
    .....
    public CustController(){
        hasAccessBasedOnQueue =  isCurrentUserMemberOfRequiredQueues();
    }

    private Boolean isCurrentUserMemberOfRequiredQueues(){
       List<String> allowedQueuesDevNames = new List<String>{
           'team_CT',
           'team_ESK'
       };
       return !([
           select Id
           from GroupMember
           where Group.DeveloperName in :allowedQueuesDevNames
               and Group.Type = 'Queue'
               and UserOrGroupId = :UserInfo.getUserId()
       ]).isEmpty();
    }
}

VF page:

....
rendered="{! AND(theCase.Status == '7', hasAccessBasedOnQueue)}
....
0

You can do something like below given you don't have any users with the same names. Below solution doesn't use API name but labels of queue.

rendered="{!AND(theCase.Status == '7', OR(theCase.owner.name == 'Queue 1', theCase.owner.name == 'Queue 2')}"

Edit

For the logged in user to be the member of the queue you can declare a variable in your controller.

public integer count {get; set;}

 count = [select count() from GroupMember where
                Group.Type = 'Queue' AND
                UserOrGroupId = :UserInfo.getUserId() AND
                Group.DeveloperName in ('team_CT', 'team_ESK')];
return count;

And write the render expression based on this variable.

rendered="{! AND(theCase.Status == '7', count > 0)}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.