I am getting an error on line 20 invalid character in identifier: Inspection__Service__c.

public with sharing class AddedServicesGrouping {

    public Inspection_Service__c[] Summaries {get; set;}

    public AddedServicesGrouping(){

        AggregateResult[] results =
                [SELECT Added_Services_Group__c AddedService, count_distinct(id) Quantity
                FROM Inspection_Service__c
                WHERE Status__c = 'Completed'
                GROUP BY Added_Services_Group__c];

        Summaries = new List<Inspection_Service__c>();

        for(AggregateResult ar: results){
            Summaries.add(new Inspection_Service__c(ar));

    public class Inspection_Service__c{

        public Integer Quantity {get; private set;}
        public String Name {get; private set;}

        public Inspection_Service__c(AggregateResult ar){
            Quantity = (Integer) ar.get('Quantity');
            Name = (String) ar.get('Added_Services_Group__c');

And I also get the error: invalid field Quantity for SObject Inspection_Service__c for this visualforce page:

<apex:page controller="AddedServicesGrouping" readOnly="true">
    <apex:repeat value="{!Summaries}" var="s">
        {!s.Name} : {!s.Quantity}<br/>

  • I don't completely understand what you are trying to do here? are you trying to make a wrapper class?
    – Tim Willis
    Mar 21, 2018 at 0:44
  • @TimWillis Looks like a wrapper class. And a well-implemented one. Mar 21, 2018 at 0:55

1 Answer 1


Declaring an Apex class with the same API name as an Sobject will lead to unexpected results like this one. Your Visualforce page is trying to bind to what it thinks is an Sobject Inspection_Service__c, which doesn't have the fields Name and Quantity you're using.

Change the name of your wrapper class and you should be able to access its properties via Visualforce, provided you include appropriate getter and setter methods or synthesize them with { get; set; }.

  • Agreed. Instead of a class called Inspection_Service__c, call the wrapper InspectionService. Mar 21, 2018 at 0:57
  • Thank you. I did try to have the name of the wrapper class 'InspectionServices,' but then I got the error message: type requires name=value pair construction on line 16
    – Sebastian
    Mar 21, 2018 at 1:01
  • That's a different issue, but I would bet you had the name of the Sobject instead of the name of the wrapper class on line 16.
    – David Reed
    Mar 21, 2018 at 2:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .