function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
John NeffJohn Neff 

Trying to use AggregateResult for the first time, getting error " Missing '<EOF>' at 'public' "

Hello,

I am trying to use AggregateResult to build a controller for a VF page.  This is the fist time that I am using this function and am recieving the error: 
Error: Compile Error: Missing '<EOF>' at 'public' at line 10 column 1

I have googled this like crazy, and seem to understand that it is because I have markup outside of the wrapper but I still can't understand how to fix it?  Can anyone help?

Here is my class: 
 
public class CurrentWeekDY{
    String Campaign {get; set;}
    String Delivery {get; set;}
        public DelSum(string c, string d){
        this.Campaign=c;
        this.Delivery=d;
        
    }
}
public List<DelSum> DelSumList = new List<DelSum>();

public List<DelSum> getDelSumOut(){

    AggregateResult[] AgR = [SELECT Campaign_TL__c, SUM(Spend__c) FROM TL_Client__c WHERE CWDelivery__c = TRUE GROUP BY Campaign_TL__c ORDER BY Campaign_TL__c]; 
    for (AggregateResult DYList : AgR) { 
        DelSumList.add(new DelSum(String.valueOf(DYList.get('Campaign_TL__c')), String.valueOf(DYList.get('expr0')), String.valueOf(DYList.get('expr1'))));
    }
    return DelSumList;
}

Thank you so much for any help!

John 
Best Answer chosen by John Neff
David @ ConfigeroDavid @ Configero
From your original code your constructor has 2 parameters on line #6:
string c - which is being copied to this.Campaign
string d - which is being copied to this.Delivery

on line #18 you are creating a new DelSum class, which is calling the constructor on line #6.  You are calling with 3 parameters, but it is only defined with 2 parameters.

what is 'expr0' supposed to be, and what is 'expr1' supposed to be?  Double check your SOQL query on line #15, make sure you are passing the right parameters in the right order on line #18, then make sure the constructor definition on line #6 matches your reference on line #18.

Does this make sense, or did I lose you with these steps?

All Answers

David @ ConfigeroDavid @ Configero
You are close!

You had a bracket on line #9 that should have been after line #18.  I moved it and reformatted the code, so please compare it to your prior code to learn where you went wrong.  You can help prevent these sorts of common mishaps by keeping your code clean, formatted, and indented.
 
public class CurrentWeekDY {
	String Campaign {get; set;}
	String Delivery {get; set;}
	public DelSum(string c, string d) {
		this.Campaign = c;
		this.Delivery = d;

	}

	public List<DelSum> DelSumList = new List<DelSum>();

	public List<DelSum> getDelSumOut() {

		AggregateResult[] AgR = [SELECT Campaign_TL__c, SUM(Spend__c) FROM TL_Client__c WHERE CWDelivery__c = TRUE GROUP BY Campaign_TL__c ORDER BY Campaign_TL__c];
		for (AggregateResult DYList : AgR) {
			DelSumList.add(new DelSum(String.valueOf(DYList.get('Campaign_TL__c')), String.valueOf(DYList.get('expr0')), String.valueOf(DYList.get('expr1'))));
		}
		return DelSumList;
	}
}

Please mark this answer as correct if it helped you. 
John NeffJohn Neff
Thank you for your help!  I can't believe I missed it, staring at it too long I guess!

Moving the bracket cleared the error, but opened up another on line 12: "Invalid type: DelSum at line 12 column 21".  I'll have to go back to the drawing board on that one!
v varaprasadv varaprasad
Hi John,

add class to above line 
 
public class   DelSum{     
String Campaign {get; set;}
	String Delivery {get; set;}
	public DelSum(string c, string d) {
		this.Campaign = c;
		this.Delivery = d;

	}
}

Hope this helps you.

Thanks
Varaprasad
David @ ConfigeroDavid @ Configero
Try this for your other issue:
public class CurrentWeekDY {
	public class DelSum {
		String Campaign {get; set;}
		String Delivery {get; set;}

		public DelSum(string c, string d) {
			this.Campaign = c;
			this.Delivery = d;
		}
	}

	public List<DelSum> DelSumList = new List<DelSum>();

	public List<DelSum> getDelSumOut() {
		AggregateResult[] AgR = [SELECT Campaign_TL__c, SUM(Spend__c) FROM TL_Client__c WHERE CWDelivery__c = TRUE GROUP BY Campaign_TL__c ORDER BY Campaign_TL__c];

		for (AggregateResult DYList : AgR) {
			DelSumList.add(new DelSum(String.valueOf(DYList.get('Campaign_TL__c')), String.valueOf(DYList.get('expr0')), String.valueOf(DYList.get('expr1'))));
		}

		return DelSumList;
	}
}

 
John NeffJohn Neff
Thank you so much for your help David, I really appreciate it!

When I try the code you supplied I am getting 
Error: Compile Error: Constructor not defined: [CurrentWeekDY.DelSum].<Constructor>(String, String, String) at line 18 column 28

 
David @ ConfigeroDavid @ Configero
From your original code your constructor has 2 parameters on line #6:
string c - which is being copied to this.Campaign
string d - which is being copied to this.Delivery

on line #18 you are creating a new DelSum class, which is calling the constructor on line #6.  You are calling with 3 parameters, but it is only defined with 2 parameters.

what is 'expr0' supposed to be, and what is 'expr1' supposed to be?  Double check your SOQL query on line #15, make sure you are passing the right parameters in the right order on line #18, then make sure the constructor definition on line #6 matches your reference on line #18.

Does this make sense, or did I lose you with these steps?
This was selected as the best answer
John NeffJohn Neff

Ohh! I can't believe I missed that!
 

I origionally had 3 parameters, then cut it down to 2 before I got stuck... and forgot to update line 18.  Thank you so much. 

Gosh I'm dense!