Example - getUserAvailabilityAllTeams

This example outputs a list of teams with user availability, giving an output as shown below.

Controller

 public class TeamAvailabilityController {

/**
* Return a list of user availability for each Distribution Engine team
**/
public List<TeamAvailabilityWrapper> getTeamAvailability() {

//List of wrapper objects to return
List<TeamAvailabilityWrapper> resultList = new List<TeamAvailabilityWrapper>();

//Get all user names from Salesforce
List<User> userList = [SELECT Name FROM User WHERE Id IN (SELECT n2de__User__c FROM n2de__Team_member__c) ORDER BY Name ASC];

//Get all DE team names from Salesforce
List<n2de__team__c> teamList = [SELECT Name FROM n2de__Team__c WHERE n2de__Is_active__c = TRUE and n2de__Is_distribute_to_queue__c = FALSE ORDER BY Name ASC];

//Call the global method to get user availability
Map<Id, Map<Id, Boolean>> teamAvailabilityMap = n2de.DistributionEngineGlobal.getUserAvailabilityAllTeams();

//Loop through the results
for (n2de__team__c thisTeam : teamList) {
Map<Id, Boolean> userAvailability = teamAvailabilityMap.get(thisTeam.Id);

TeamAvailabilityWrapper taw = new TeamAvailabilityWrapper();
taw.teamName = thisTeam.name;

for (User thisUser : userList) {
if (!userAvailability.containsKey(thisUser.Id)) {
continue;
}

UserAvailabilityWrapper uaw = new UserAvailabilityWrapper();
uaw.userName = thisUser.name;
uaw.isOnline = userAvailability.get(thisUser.Id);

taw.userAvailability.add(uaw);
}

resultList.add(taw);
}
return resultList;
}

public class TeamAvailabilityWrapper {
public String teamName {get;set;}
public List<UserAvailabilityWrapper> userAvailability {get;set;}

public TeamAvailabilityWrapper(){
this.userAvailability = new List<UserAvailabilityWrapper>();
}
}

public class UserAvailabilityWrapper {
public String userName {get;set;}
public boolean isOnline {get;set;}
}
}

Visualforce page

<apex:page controller="TeamAvailabilityController">
<style>
.online{
color: green;
font-weight: bold;
font-size: 12pt;
}
.offline{
color: gray;
}
</style>
<ul>
<apex:repeat value="{!teamAvailability}" var="team">
<li>
{!team.teamName}
<ul>
<apex:repeat value="{!team.userAvailability}" var="user">
<li class="{!IF(user.isOnline, 'online', 'offline')}">{!user.userName} - {!IF(user.isOnline, 'Online', 'Offline')}</li>
</apex:repeat>
</ul>
</li>
</apex:repeat>
</ul>
</apex:page>

How did we do?

Example - getAvailabilityByUser

Contact