Skip to main content
deleted 6 characters in body
Source Link
Chris Duncombe
  • 24.3k
  • 13
  • 77
  • 116
public class myController {
    
    public list<SalesRepWrapper> wraps              {get; private set;}

    Public list<string> getMonthList(){
        list<string> months = new list<String>();
    
        for(Integer i = system.today().month(); i <= 12; i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year(), i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
        for(Integer i = 1; i < system.today().month(); i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year() + 1, i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
            return months;
    }

    public myController(){
        buildData();
    }

    public void buildData(){
        list<User_Stats__c> stats = [Select Id, Sales_Rep__c, Month_Number__c, Year__c, Total Rental_Revenue_Actual__c
                                        From User_Stats__c 
                                        Where (Month_Number__c >= system.today().month() && Year__c == system.today().year()) Or
                                        (Month_Number__c < system.today().month() && Year__c == system.today().year() + 1)
                                        Order By Sales_Rep__c, Year__c, Month_Number__c];
    
        set<Id> UserIDs = new set<Id>();                            
        for(User_Stats__c stat : stats){
            userIDs.add(Sales_Rep__c);
        }

        map<Id,User> userMap = new map<Id,User>([Select Id, Name From User Where Id In: userIDs]);

        map<Id,list<decimal>> rep2ActualsMap = new map<Id,list<decimal>>();

        for(User_Stats__c stat : stats){
            if(!rep2ActualsMap.containsKey(stat.Sales_Rep__c){
                rep2ActualsMap.put(stat.Sales_Rep__c, new list<User_Stats__c>list<Decimal>());
            }
            rep2ActualsMap.get(stat.Sales_Rep__c).add(stat.Rental_Revenue_Actual__c);
        }
        wraps = new list<SalesRepWrapper>();
        for(Id uId : rep2ActualsMap.keySet()){
            wrap.add(new SalesRepWrapper(userMap.get(uId), rep2ActualsMap.get(uId)));
        }
    }

    public Class SalesRepWrapper {

        public list<decimal> actuals            {get;set;}
        public User rep                         {get;set}

        public SalesRepWrapper(User u, list<decimal> vals){
            this.rep = u;
            this.actuals = vals;
        }
    }

}
public class myController {
    
    public list<SalesRepWrapper> wraps              {get; private set;}

    Public list<string> getMonthList(){
        list<string> months = new list<String>();
    
        for(Integer i = system.today().month(); i <= 12; i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year(), i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
        for(Integer i = 1; i < system.today().month(); i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year() + 1, i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
            return months;
    }

    public myController(){
        buildData();
    }

    public void buildData(){
        list<User_Stats__c> stats = [Select Id, Sales_Rep__c, Month_Number__c, Year__c, Total Rental_Revenue_Actual__c
                                        From User_Stats__c 
                                        Where (Month_Number__c >= system.today().month() && Year__c == system.today().year()) Or
                                        (Month_Number__c < system.today().month() && Year__c == system.today().year() + 1)
                                        Order By Sales_Rep__c, Year__c, Month_Number__c];
    
        set<Id> UserIDs = new set<Id>();                            
        for(User_Stats__c stat : stats){
            userIDs.add(Sales_Rep__c);
        }

        map<Id,User> userMap = new map<Id,User>([Select Id, Name From User Where Id In: userIDs]);

        map<Id,list<decimal>> rep2ActualsMap = new map<Id,list<decimal>>();

        for(User_Stats__c stat : stats){
            if(!rep2ActualsMap.containsKey(stat.Sales_Rep__c){
                rep2ActualsMap.put(stat.Sales_Rep__c, new list<User_Stats__c>());
            }
            rep2ActualsMap.get(stat.Sales_Rep__c).add(stat.Rental_Revenue_Actual__c);
        }
        wraps = new list<SalesRepWrapper>();
        for(Id uId : rep2ActualsMap.keySet()){
            wrap.add(new SalesRepWrapper(userMap.get(uId), rep2ActualsMap.get(uId)));
        }
    }

    public Class SalesRepWrapper {

        public list<decimal> actuals            {get;set;}
        public User rep                         {get;set}

        public SalesRepWrapper(User u, list<decimal> vals){
            this.rep = u;
            this.actuals = vals;
        }
    }

}
public class myController {
    
    public list<SalesRepWrapper> wraps              {get; private set;}

    Public list<string> getMonthList(){
        list<string> months = new list<String>();
    
        for(Integer i = system.today().month(); i <= 12; i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year(), i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
        for(Integer i = 1; i < system.today().month(); i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year() + 1, i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
            return months;
    }

    public myController(){
        buildData();
    }

    public void buildData(){
        list<User_Stats__c> stats = [Select Id, Sales_Rep__c, Month_Number__c, Year__c, Total Rental_Revenue_Actual__c
                                        From User_Stats__c 
                                        Where (Month_Number__c >= system.today().month() && Year__c == system.today().year()) Or
                                        (Month_Number__c < system.today().month() && Year__c == system.today().year() + 1)
                                        Order By Sales_Rep__c, Year__c, Month_Number__c];
    
        set<Id> UserIDs = new set<Id>();                            
        for(User_Stats__c stat : stats){
            userIDs.add(Sales_Rep__c);
        }

        map<Id,User> userMap = new map<Id,User>([Select Id, Name From User Where Id In: userIDs]);

        map<Id,list<decimal>> rep2ActualsMap = new map<Id,list<decimal>>();

        for(User_Stats__c stat : stats){
            if(!rep2ActualsMap.containsKey(stat.Sales_Rep__c){
                rep2ActualsMap.put(stat.Sales_Rep__c, new list<Decimal>());
            }
            rep2ActualsMap.get(stat.Sales_Rep__c).add(stat.Rental_Revenue_Actual__c);
        }
        wraps = new list<SalesRepWrapper>();
        for(Id uId : rep2ActualsMap.keySet()){
            wrap.add(new SalesRepWrapper(userMap.get(uId), rep2ActualsMap.get(uId)));
        }
    }

    public Class SalesRepWrapper {

        public list<decimal> actuals            {get;set;}
        public User rep                         {get;set}

        public SalesRepWrapper(User u, list<decimal> vals){
            this.rep = u;
            this.actuals = vals;
        }
    }

}
added 29 characters in body
Source Link
Chris Duncombe
  • 24.3k
  • 13
  • 77
  • 116
public class myController {
    
    public list<SalesRepWrapper> wraps              {get; private set;}

    Public list<string> getMonthList(){
        list<string> months = new list<String>();
    
        for(Integer i = system.today().month(); i <= 12; i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year(), i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
        for(Integer i = 1; i < system.today().month(); i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year() + 1, i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
            return months;
    }

    public constructorNamemyController(){
        buildData();
    }

    public void buildData(){
        list<User_Stats__c> stats = [Select Id, Sales_Rep__c, Month_Number__c, Year__c, Total Rental_Revenue_Actual__c
                                        From User_Stats__c 
                                        Where (Month_Number__c >= system.today().month() && Year__c == system.today().year()) Or
                                        (Month_Number__c < system.today().month() && Year__c == system.today().year() + 1)
                                        Order By Sales_Rep__c, Year__c, Month_Number__c];
    
        set<Id> UserIDs = new set<Id>();                            
        for(User_Stats__c stat : stats){
            userIDs.add(Sales_Rep__c);
        }

        map<Id,User> userMap = new map<Id,User>([Select Id, Name From User Where Id In: userIDs]);

        map<Id,list<decimal>> rep2ActualsMap = new map<Id,list<decimal>>();

        for(User_Stats__c stat : stats){
            if(!rep2ActualsMap.containsKey(stat.Sales_Rep__c){
                rep2ActualsMap.put(stat.Sales_Rep__c, new list<User_Stats__c>());
            }
            rep2ActualsMap.get(stat.Sales_Rep__c).add(stat.Rental_Revenue_Actual__c);
        }
        wraps = new list<SalesRepWrapper>();
        for(Id uId : rep2ActualsMap.keySet()){
            wrap.add(new SalesRepWrapper(userMap.get(uId), rep2ActualsMap.get(uId)));
        }
    }

    public Class SalesRepWrapper {

        public list<decimal> actuals            {get;set;}
        public User rep                         {get;set}

        public SalesRepWrapper(User u, list<decimal> vals){
            this.rep = u;
            this.actuals = vals;
        }
    }

}
public class myController {
    
    public list<SalesRepWrapper> wraps              {get; private set;}

    Public list<string> getMonthList(){
        list<string> months = new list<String>();
    
        for(Integer i = system.today().month(); i <= 12; i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year(), i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
        for(Integer i = 1; i < system.today().month(); i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year() + 1, i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
    }

    public constructorName(){
        buildData();
    }

    public void buildData(){
        list<User_Stats__c> stats = [Select Id, Sales_Rep__c, Month_Number__c, Year__c, Total Rental_Revenue_Actual__c
                                        From User_Stats__c 
                                        Where (Month_Number__c >= system.today().month() && Year__c == system.today().year()) Or
                                        (Month_Number__c < system.today().month() && Year__c == system.today().year() + 1)
                                        Order By Sales_Rep__c, Year__c, Month_Number__c];
    
        set<Id> UserIDs = new set<Id>();                            
        for(User_Stats__c stat : stats){
            userIDs.add(Sales_Rep__c);
        }

        map<Id,User> userMap = new map<Id,User>([Select Id, Name From User Where Id In: userIDs]);

        map<Id,list<decimal>> rep2ActualsMap = new map<Id,list<decimal>>();

        for(User_Stats__c stat : stats){
            if(!rep2ActualsMap.containsKey(stat.Sales_Rep__c){
                rep2ActualsMap.put(stat.Sales_Rep__c, new list<User_Stats__c>());
            }
            rep2ActualsMap.get(stat.Sales_Rep__c).add(stat.Rental_Revenue_Actual__c);
        }
        wraps = new list<SalesRepWrapper>();
        for(Id uId : rep2ActualsMap.keySet()){
            wrap.add(new SalesRepWrapper(userMap.get(uId), rep2ActualsMap.get(uId)));
        }
    }

    public Class SalesRepWrapper {

        public list<decimal> actuals            {get;set;}
        public User rep                         {get;set}

        public SalesRepWrapper(User u, list<decimal> vals){
            this.rep = u;
            this.actuals = vals;
        }
    }

}
public class myController {
    
    public list<SalesRepWrapper> wraps              {get; private set;}

    Public list<string> getMonthList(){
        list<string> months = new list<String>();
    
        for(Integer i = system.today().month(); i <= 12; i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year(), i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
        for(Integer i = 1; i < system.today().month(); i++){
            months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year() + 1, i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
        }
            return months;
    }

    public myController(){
        buildData();
    }

    public void buildData(){
        list<User_Stats__c> stats = [Select Id, Sales_Rep__c, Month_Number__c, Year__c, Total Rental_Revenue_Actual__c
                                        From User_Stats__c 
                                        Where (Month_Number__c >= system.today().month() && Year__c == system.today().year()) Or
                                        (Month_Number__c < system.today().month() && Year__c == system.today().year() + 1)
                                        Order By Sales_Rep__c, Year__c, Month_Number__c];
    
        set<Id> UserIDs = new set<Id>();                            
        for(User_Stats__c stat : stats){
            userIDs.add(Sales_Rep__c);
        }

        map<Id,User> userMap = new map<Id,User>([Select Id, Name From User Where Id In: userIDs]);

        map<Id,list<decimal>> rep2ActualsMap = new map<Id,list<decimal>>();

        for(User_Stats__c stat : stats){
            if(!rep2ActualsMap.containsKey(stat.Sales_Rep__c){
                rep2ActualsMap.put(stat.Sales_Rep__c, new list<User_Stats__c>());
            }
            rep2ActualsMap.get(stat.Sales_Rep__c).add(stat.Rental_Revenue_Actual__c);
        }
        wraps = new list<SalesRepWrapper>();
        for(Id uId : rep2ActualsMap.keySet()){
            wrap.add(new SalesRepWrapper(userMap.get(uId), rep2ActualsMap.get(uId)));
        }
    }

    public Class SalesRepWrapper {

        public list<decimal> actuals            {get;set;}
        public User rep                         {get;set}

        public SalesRepWrapper(User u, list<decimal> vals){
            this.rep = u;
            this.actuals = vals;
        }
    }

}
fixed typo
Source Link
Chris Duncombe
  • 24.3k
  • 13
  • 77
  • 116

This code also makes a fairly important assumption about your data model

This code also makes a fairly important about your data model

This code also makes a fairly important assumption about your data model

Source Link
Chris Duncombe
  • 24.3k
  • 13
  • 77
  • 116
Loading