+ Start a Discussion
StaciStaci 

unexpected token 'class'

public class wrapperClassController {
    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
    public class lntypes {
        public License_Numbers__c con {get; set;}
        public Boolean tobeEdited {get; set;}

        //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
        public lntypes(License_Numbers__c c) {
            con = c;
            tobeEdited = false;
        }
    }
        
    //Our collection of the class/wrapper objects cContact
    public List<lntypes> licList {get; set;}

    //This method uses a simple SOQL query to return a List of Contacts
    public List<lntypes> getLicenseList17() {
        if(licList == null) {
            licList = new List<lntypes>();
            for(License_Numbers__c c:[select id, Name, X2016_Cost__c, Business_Unit__c, X2016_Starting_Amount__c, X2016_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c FROM License_Numbers__c ]) {

                // As each contact is processed we create a new cContact object and add it to the contactList
                licList.add(new lntypes(c));
            }
        }
        return licList;
    }
    public PageReference saveRecord() {

        //We create a new list of Contacts that we be populated only with Contacts if they are selected
        List<License_Numbers__c> selectedTypes = new List<License_Numbers__c>();

        //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
        for(lntypes cCon: getLicenseList17()) {
            if(cCon.tobeEdited == true) {
                selectedTypes.add(cCon.con);
            }
        }

        // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
        System.debug('These are the selected Contacts...');
        for(License_Numbers__c con: selectedTypes) {
            system.debug(con);
        }
        contactList=null; // we need this line if we performed a write operation  because getContacts gets a fresh list now
        return null;
    }

    
}
I have a wrapper class that is suppose to loop through some license records and then if one is edited to update it.  

Just copying the wrapper class from SFCD and changing the variable to match what I need I'm getting a unexpected token 'class'  at line 70 column 11

Line 70
public class lntypes {

What is my problem?
 
Best Answer chosen by Staci
Ashish KumarAshish Kumar
Hey Staci, Are you trying to create a wrapper class ( lntypes) inside a class (wrapperClassController) which is already inside another class (LicenseList) . I don't think its a correct approach to follow. If you want to create the wrapper class then remove the wrapperClassController Initialization. I have edited the code please check if it works for you. public with sharing class LicenseList { private final License_Numbers__c ln; public user currentuser{get;set;} public LicenseList(ApexPages.StandardSetController controller) { currentuser=new User(); currentuser=[Select Id, Business_Unit_new__c from User where Id=:userinfo.getuserId()]; this.ln = (License_Numbers__c)controller.getRecord(); } public ApexPages.StandardSetController LicenseRecords{ get { if(LicenseRecords == null) { return new ApexPages.StandardSetController(Database.getQueryLocator( [SELECT ln.Name, ln.X2016_Cost__c, ln.X2016_Subtotal__c, ln.Business_Unit__c, ln.X2016_Starting_Amount__c, ln.BMS_Code__c, ln.License_Type__c, ln.Monthly_Unit_Price__c, ln.Org__c, ln.Running_License_Total__c FROM License_Numbers__c ln where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2016' ORDER BY ln.License_Type__c])); } return LicenseRecords; } private set; } //Shows the current list of licenses public List getLicenseList() { return (List) LicenseRecords.getRecords(); } //------------------------------------------------------------------------------------------- private integer totalRecs = 0; private integer OffsetSize = 0; private integer LimitSize= 10; public void FirstPage() { OffsetSize = 0; } public void previous() { OffsetSize = OffsetSize - LimitSize; } public void next() { OffsetSize = OffsetSize + LimitSize; } public void LastPage() { OffsetSize = totalrecs - math.mod(totalRecs,LimitSize); } public boolean getprev() { if(OffsetSize == 0) return true; else return false; } public boolean getnxt() { if((OffsetSize + LimitSize) > totalRecs) return true; else return false; } //Our collection of the class/wrapper objects cContact public List LicList {get;set;} //This method uses a simple SOQL query to return a List of Contacts public List getLicenseList17(){ if(licList == null) { licList = new List(); for(License_Numbers__c c:[select id, Name, X2016_Cost__c, Business_Unit__c, X2016_Starting_Amount__c, X2016_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c FROM License_Numbers__c ]) { //As each contact is processed we create a new cContact object and add it to the contactList licList.add(new lntypes(c)); } } return licList; } public PageReference saveRecord(){ //We create a new list of Contacts that we be populated only with Contacts if they are selected List selectedTypes = new List(); //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list for(lntypes cCon: getLicenseList17()) { if(cCon.tobeEdited == true) { selectedTypes.add(cCon.con); } } // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc System.debug('These are the selected Contacts...'); for(License_Numbers__c con: selectedTypes) { system.debug(con); } licList=null; // we need this line if we performed a write operation because getContacts gets a fresh list now return null; } public class lntypes { public License_Numbers__c con {get; set;} public Boolean tobeEdited {get; set;} //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false public lntypes(License_Numbers__c c) { con = c; tobeEdited = false; } } } Ashish

All Answers

Harish RamachandruniHarish Ramachandruni
Hi

check all  {  open and closed places  and check  are writing class in in side methode or some like that . best to copy past in developer counsole once .

If it is passible to show code .


Regards,

Harish.R
StaciStaci
@Harish rao 25
all {} are counted for and matching.  Dev Console only shows unexpected token: 'class' as well

Not sure what you mean by "check are writing class inside method"
 
Ashish KumarAshish Kumar
Hi Staci,

Can you please tell if the above code is the only code in your controller class? Because i can see only 51 lines and error message says that you are getting error on line 70.
also at line 46 in above code, you have not declared any variable named as contactList.
StaciStaci
@ashish Kumar

its only the wrapper class, I fixed line 46, that was left over from me copying SFDC's wrapper class.  Still doesn't work
Ashish KumarAshish Kumar
@staci There are only 51 lines of code. Then how it is showing error on line no 70. Also I copied the above posted code and changed the custom object name to contact and it was working fine. Can you please share the screenshot of the error in developer console.
StaciStaci
@Ashish Kumar

Here's is all the code
public with sharing class LicenseList {
private final License_Numbers__c ln;
public user currentuser{get;set;}

public LicenseList(ApexPages.StandardSetController controller) {

currentuser=new User();
     currentuser=[Select Id, Business_Unit_new__c from User where Id=:userinfo.getuserId()];
     
     
this.ln = (License_Numbers__c)controller.getRecord();
}
public ApexPages.StandardSetController LicenseRecords{
get {
if(LicenseRecords == null) {

return new ApexPages.StandardSetController(Database.getQueryLocator(
[SELECT ln.Name, ln.X2016_Cost__c, ln.X2016_Subtotal__c, ln.Business_Unit__c, ln.X2016_Starting_Amount__c, ln.BMS_Code__c, ln.License_Type__c, ln.Monthly_Unit_Price__c, ln.Org__c, ln.Running_License_Total__c FROM License_Numbers__c ln where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2016' ORDER BY ln.License_Type__c]));
}
return LicenseRecords;
}
private set;
}
//Shows the current list of licenses
public List<License_Numbers__c> getLicenseList() 
{
return (List<License_Numbers__c>) LicenseRecords.getRecords();
}
//-------------------------------------------------------------------------------------------


private integer totalRecs = 0;
private integer OffsetSize = 0;
private integer LimitSize= 10;

public void FirstPage()
{
OffsetSize = 0;
}
public void previous()
{
OffsetSize = OffsetSize - LimitSize;
}
public void next()
{
OffsetSize = OffsetSize + LimitSize;
}
public void LastPage()
{
OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
}
public boolean getprev()
{
if(OffsetSize == 0)
return true;
else
return false;
}
public boolean getnxt()
{
if((OffsetSize + LimitSize) > totalRecs)
return true;
else
return false;
}

//-------------------------------------------------------------------------------------------------
public class wrapperClassController {
   
    //Our collection of the class/wrapper objects cContact
    public List<lntypes> LicList {get;set;}
    
    //This method uses a simple SOQL query to return a List of Contacts
    public List<lntypes> getLicenseList17(){
        if(licList == null) {
            licList = new List<lntypes>();
            for(License_Numbers__c c:[select id, Name, X2016_Cost__c, Business_Unit__c, X2016_Starting_Amount__c, X2016_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c FROM License_Numbers__c ]) {

                //As each contact is processed we create a new cContact object and add it to the contactList
                licList.add(new lntypes(c));
            }
        }
        return licList;
    }
    public PageReference saveRecord(){

        //We create a new list of Contacts that we be populated only with Contacts if they are selected
        List<License_Numbers__c> selectedTypes = new List<License_Numbers__c>();

        //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
        for(lntypes cCon: getLicenseList17()) {
            if(cCon.tobeEdited == true) {
                selectedTypes.add(cCon.con);
            }
        }

        // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
        System.debug('These are the selected Contacts...');
        for(License_Numbers__c con: selectedTypes) {
            system.debug(con);
        }
        licList=null; // we need this line if we performed a write operation  because getContacts gets a fresh list now
        return null;
    }
            
   public class lntypes {
        public License_Numbers__c con {get; set;}
        public Boolean tobeEdited {get; set;}

        //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
        public lntypes(License_Numbers__c c) {
            con = c;
            tobeEdited = false;
        }
    }
        
   } 
}

 
StaciStaci
public class lntypes { is the line it errors on
Ashish KumarAshish Kumar
Hey Staci, Are you trying to create a wrapper class ( lntypes) inside a class (wrapperClassController) which is already inside another class (LicenseList) . I don't think its a correct approach to follow. If you want to create the wrapper class then remove the wrapperClassController Initialization. I have edited the code please check if it works for you. public with sharing class LicenseList { private final License_Numbers__c ln; public user currentuser{get;set;} public LicenseList(ApexPages.StandardSetController controller) { currentuser=new User(); currentuser=[Select Id, Business_Unit_new__c from User where Id=:userinfo.getuserId()]; this.ln = (License_Numbers__c)controller.getRecord(); } public ApexPages.StandardSetController LicenseRecords{ get { if(LicenseRecords == null) { return new ApexPages.StandardSetController(Database.getQueryLocator( [SELECT ln.Name, ln.X2016_Cost__c, ln.X2016_Subtotal__c, ln.Business_Unit__c, ln.X2016_Starting_Amount__c, ln.BMS_Code__c, ln.License_Type__c, ln.Monthly_Unit_Price__c, ln.Org__c, ln.Running_License_Total__c FROM License_Numbers__c ln where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2016' ORDER BY ln.License_Type__c])); } return LicenseRecords; } private set; } //Shows the current list of licenses public List getLicenseList() { return (List) LicenseRecords.getRecords(); } //------------------------------------------------------------------------------------------- private integer totalRecs = 0; private integer OffsetSize = 0; private integer LimitSize= 10; public void FirstPage() { OffsetSize = 0; } public void previous() { OffsetSize = OffsetSize - LimitSize; } public void next() { OffsetSize = OffsetSize + LimitSize; } public void LastPage() { OffsetSize = totalrecs - math.mod(totalRecs,LimitSize); } public boolean getprev() { if(OffsetSize == 0) return true; else return false; } public boolean getnxt() { if((OffsetSize + LimitSize) > totalRecs) return true; else return false; } //Our collection of the class/wrapper objects cContact public List LicList {get;set;} //This method uses a simple SOQL query to return a List of Contacts public List getLicenseList17(){ if(licList == null) { licList = new List(); for(License_Numbers__c c:[select id, Name, X2016_Cost__c, Business_Unit__c, X2016_Starting_Amount__c, X2016_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c FROM License_Numbers__c ]) { //As each contact is processed we create a new cContact object and add it to the contactList licList.add(new lntypes(c)); } } return licList; } public PageReference saveRecord(){ //We create a new list of Contacts that we be populated only with Contacts if they are selected List selectedTypes = new List(); //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list for(lntypes cCon: getLicenseList17()) { if(cCon.tobeEdited == true) { selectedTypes.add(cCon.con); } } // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc System.debug('These are the selected Contacts...'); for(License_Numbers__c con: selectedTypes) { system.debug(con); } licList=null; // we need this line if we performed a write operation because getContacts gets a fresh list now return null; } public class lntypes { public License_Numbers__c con {get; set;} public Boolean tobeEdited {get; set;} //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false public lntypes(License_Numbers__c c) { con = c; tobeEdited = false; } } } Ashish
This was selected as the best answer
StaciStaci
Thank you @Ashish Kumar, that worked, but now getting this error Error: Unknown property 'LicenseList.mylist.Id' on the vf page
Ashish KumarAshish Kumar
@staci There is nothing (a variable or a list) in your code which is named as mylist and you are trying to use it in your vf page.. either change the name to the list which you are trying to use or create mylist in your controller class.
StaciStaci
@Ashish Kumar

I had renamed lntypes to mylist because I got the same error with lntypes.  
Error: Unknown property 'LicenseList.lntypes.Id'

I guess I don't understand what this is doing / connected to my vf page.  is lntypes just a name?  Am I supposed to refer to it in my vf page somewhere?
public class lntypes { public License_Numbers__c con {get; set;} public Boolean tobeEdited {get; set;}
Ashish KumarAshish Kumar
lntypes is just a class name and you can access the variables declared inside that class,for example lntypes.con.id or lntypes.con.anyfieldofobject and as per your code you can do something like this on your vf page. Licenselist17.lntypes.con or licenselist17.lntypes.con.id
StaciStaci
@Ashish Kumar
Thank you so much for your patience and explanation!  I've got it working now!!!