Sample code for blog post on exporting Queue members as Excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class QueueMembersController { | |
// selected queue whose members to view | |
public ID queueId { get; set; } | |
// provide queue name to show on page | |
public Group selectedQueue { | |
get { | |
return [ | |
SELECT | |
id, name | |
FROM | |
Group | |
WHERE | |
id = :queueId | |
]; | |
} | |
} | |
// list of all active queue members | |
public List<User> queueMembers { | |
get { | |
return [ | |
SELECT | |
id, firstName, lastName, alias, username, email, userRole.name, profile.name | |
FROM | |
User | |
WHERE | |
id IN ( SELECT userOrGroupId FROM GroupMember WHERE groupId = :queueId ) | |
AND | |
isActive = true | |
]; | |
} | |
} | |
/** | |
* Controller | |
*/ | |
public QueueMembersController() { | |
queueId = ApexPages.currentPage().getParameters().get('queueId'); | |
} | |
public PageReference refresh() { | |
return null; | |
} | |
// picklist of queues whose members to view | |
public List<SelectOption> getQueueOptions() { | |
List<SelectOption> options = new List<SelectOption>(); | |
options.add( new SelectOption( '', '- Select -' ) ); | |
for ( Group grp : [ | |
SELECT | |
id, name | |
FROM | |
Group | |
WHERE | |
type = 'Queue' | |
ORDER BY | |
name | |
] ) { | |
options.add( new SelectOption( grp.id, grp.name ) ); | |
} | |
return options; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="QueueMembersController" title="Queue Members" sidebar="false" docType="html-5.0"> | |
<apex:form id="mainForm"> | |
<apex:pageBlock id="mainPageBlock" title="Queue Members"> | |
<apex:pageMessages /> | |
<apex:pageBlockButtons> | |
<apex:commandButton value="Export Details" | |
onclick="window.open('{!URLFOR($Page.QueueMembersExcelPage, null, [ queueId = queueId ])}');" | |
rendered="{!(queueId != null)}"/> | |
<apex:commandButton value="Manage Queue" | |
onclick="window.open('{!URLFOR("/p/own/Queue/d", null, [ id= queueId, setupid = "Queues" ])}');" | |
rendered="{!(queueId != null)}"/> | |
</apex:pageBlockButtons> | |
<apex:pageBlockSection> | |
<apex:pageBlockSectionItem> | |
<b>Queue:</b> | |
<apex:selectList value="{!queueId}" size="1"> | |
<apex:selectOptions value="{!queueOptions}"/> | |
<apex:actionSupport event="onchange" action="{!refresh}" reRender="mainForm"/> | |
</apex:selectList> | |
</apex:pageBlockSectionItem> | |
</apex:pageBlockSection> | |
<apex:variable var="rowCounter" value="1"/> | |
<apex:pageBlockTable value="{!queueMembers}" var="user" rendered="{!(queueId != null)}"> | |
<apex:column headerValue="#"> | |
<apex:outputText value="{!rowCounter}"/>. | |
<apex:variable var="rowCounter" value="{!VALUE(rowCounter) + 1}"/> | |
</apex:column> | |
<apex:column headerValue="Name"> | |
<apex:outputLink value="/{!user.id}"> | |
<apex:outputText value="{0} {1}"> | |
<apex:param value="{!user.firstName}"/> | |
<apex:param value="{!user.lastName}"/> | |
</apex:outputText> | |
</apex:outputLink> | |
</apex:column> | |
<apex:column value="{!user.alias}"/> | |
<apex:column value="{!user.username}"/> | |
<apex:column value="{!user.email}"/> | |
<apex:column value="{!user.userRole.name}" headerValue="Role"/> | |
<apex:column value="{!user.profile.name}" headerValue="Profile"/> | |
</apex:pageBlockTable> | |
</apex:pageBlock> | |
</apex:form> | |
</apex:page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
How to create excel file in visualforce. | |
http://help.salesforce.com/apex/HTViewSolution?id=000003176&language=en_US | |
--> | |
<apex:page controller="QueueMembersController" contentType="application/vnd.ms-excel#QueueMembersExport.xls" cache="true"> | |
<apex:pageBlock > | |
<apex:pageBlockTable value="{!queueMembers}" var="user"> | |
<apex:column headerValue="Queue" value="{!selectedQueue.name}"/> | |
<apex:column value="{!user.firstName}"/> | |
<apex:column value="{!user.lastName}"/> | |
<apex:column value="{!user.alias}"/> | |
<apex:column value="{!user.username}"/> | |
<apex:column value="{!user.email}"/> | |
<apex:column value="{!user.userRole.name}" headerValue="Role"/> | |
<apex:column value="{!user.profile.name}" headerValue="Profile"/> | |
</apex:pageBlockTable> | |
</apex:pageBlock> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment