Skip to content

Instantly share code, notes, and snippets.

@justin-lyon
Last active April 16, 2020 19:42
Show Gist options
  • Save justin-lyon/753fa6173f372a072ab6351519949221 to your computer and use it in GitHub Desktop.
Save justin-lyon/753fa6173f372a072ab6351519949221 to your computer and use it in GitHub Desktop.
public class DeviceCount {
  private Id accountId;
  private String typeName;
  private Integer count;

  public DeviceCount (Id accountId, String typeName, Integer count) {
    this.accountId = accountId;
    this.typeName = typeName;
    this.count = count;
  }
  
  public DeviceCount(AggregateResult ar) {
    this(
      (Id)ar.get('accountId'),
      String.valueOf(ar.get('typeName'),
      Integer.valueOf(ar.get('count'));
  }

  public String getKey() { return buildKey(accountId, typeName); }

  public String getCount() { return this.count; }

  public static String buildKey (Id accountId, String typeName) {
    return accountId + '-' + typeName);
  }
}
Map<String, Integer> deviceCounts = new Map<String, Integer>();
// for agg results 
DeviceCount dc = new DeviceCount(accId, typeName, count);
deviceCounts.put(dc.getName(), dc.getCount());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment