Example - getAvailabilityByUser

This example outputs a list of teams with user availability for the selected user.

Controller

public class UserAvailabilityController {

public Id selectedUser {get;set;}

/**
* Get a list of all users involved with DE teams
*/
public List<SelectOption> getUserOptions() {
List<User> users = [SELECT Name FROM User WHERE Id in (SELECT n2de__User__c FROM n2de__Team_member__c) ORDER BY Name ASC];
List<SelectOption> userOptions = new List<SelectOption>();
for (User u : users) {
userOptions.add(new SelectOption(u.Id, u.Name));
}
return userOptions;
}

/**
* Action for selecting a user
*/
public PageReference selectUser() {
return null;
}

/**
* Get the availability by team for the selected user Id
*/
public List<UserAvailabilityWrapper> getUserAvailability() {
List<UserAvailabilityWrapper> resultList = new List<UserAvailabilityWrapper>();

if (selectedUser == null) {
return resultList;
}

//Get a map of DE teams
Map<Id, n2de__Team__c> teamMap = new Map<Id, n2de__Team__c>([SELECT Id, Name FROM n2de__Team__c WHERE n2de__Is_active__c = TRUE AND n2de__Is_distribute_to_queue__c = FALSE ORDER BY Name ASC]);

//Get the availability of this user
Map<Id, Boolean> userAvailabilityMap = n2de.DistributionEngineGlobal.getAvailabilityByUser(selectedUser);

//Loop through the user availability map by team
for (Id teamId : userAvailabilityMap.keySet()) {
//If this team isn't in the map then ignore (it may be inactive)
n2de__Team__c thisTeam = teamMap.get(teamId);
if (thisTeam == null) {
continue;
}

UserAvailabilityWrapper uaw = new UserAvailabilityWrapper();
uaw.teamName = thisTeam.name;
uaw.isOnline = userAvailabilityMap.get(teamId);

resultList.add(uaw);
}

return resultList;
}

public class UserAvailabilityWrapper {
public String teamName {get;set;}
public Boolean isOnline {get;set;}
}
}

Visualforce Page

<apex:page controller="UserAvailabilityController">
<style>
.online{
color: green;
font-weight: bold;
font-size: 12pt;
}
.offline{
color: gray;
}
</style>
<apex:form>
<apex:selectList value="{!selectedUser}">
<apex:selectOptions value="{!userOptions}" />
<apex:actionSupport rerender="pnlTeams" action="{!selectUser}" event="onchange" />
</apex:selectList>
<apex:outputPanel id="pnlTeams">
<ul>
<apex:repeat value="{!userAvailability}" var="team">
<li class="{!IF(team.isOnline, 'online', 'offline')}">{!team.teamName} - {!IF(team.isOnline, 'Online', 'Offline')}</li>
</apex:repeat>
</ul>
</apex:outputPanel>
</apex:form>
</apex:page>

How did we do?

Availability API

Example - getUserAvailabilityAllTeams

Contact