1

below is the Wrapper class for selecting a record from the results. i am getting the Compile error:

unexpected token: 'List

kindly correct me where i am going wrong.

public PageReference processSelected() {

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

    //We will cycle through our list of cCondo and will check to see if the selected property is set to true, if it is we add the Condo to the selectedCondo list
    for(List<Condo__c> cCondo: search()) {
        if(cCondo.selected == true) {
            selectedCondo.add(List<Condo__c> cCondo.List<Condo__c> Cond);
        }
    }

This is Below is the search Controller :

public with sharing class Condosearchcontroller { 
public Condosearchcontroller() {

}
Public List<Lead> addtoLead {get;set;}
public list <Condo__c> Cond {get;set;}  
public string beds {get;set;} 
public string squarefootage {get;set;}
public Integer SFminimum {get;set;}
public Integer SFmaximum {get;set;}
public string InitialListPrice {get;set;}
public Integer ILPminimum {get;set;}
public Integer ILPmaximum {get;set;}
public boolean selected {get;set;} 

public Condosearchcontroller(ApexPages.StandardController controller) {
}  
public List<SelectOption> getbedsOptions() {
    List<SelectOption> bedsoptions = new List<SelectOption>();
    bedsoptions.add(new SelectOption('','ALL'));
    bedsoptions.add(new SelectOption('0','0'));
    bedsoptions.add(new SelectOption('1','1'));
    bedsoptions.add(new SelectOption('2','2'));
    bedsoptions.add(new SelectOption('3','3'));

    return bedsoptions;
  }
public List<Condo__c> Search(){
   Integer SFmin = Integer.valueof(SFminimum);
   Integer SFmax = Integer.Valueof(SFmaximum);
   Integer ILPmin = Integer.valueof(ILPminimum);
   Integer ILPmax = Integer.valueof(ILPmaximum);

    string searchquery= 'select      name,Beds__c,Square_Footage__c,Initial_List_Price__c,Status__c from Condo__c    where name!=null and Status__c in (\'Available\',\'Unsold\') ';
       if (beds >= '0' && SFminimum == 0 && SFmaximum == 0 && ILPminimum == 0 && ILPmaximum == 0)
               searchquery+= ' and Beds__c = '+beds+'';

            if (beds != '0' && SFminimum > 0 && SFmaximum > 0 && ILPminimum == 0 && ILPmaximum == 0) 

               searchquery+= ' and Square_Footage__c >= :SFmin and Square_Footage__c <= :SFmax ';

            if (beds >= '0' && SFminimum > 0 && SFmaximum > 0 && ILPminimum == 0 && ILPmaximum == 0)

                searchquery+= ' and Beds__c = '+beds+' and Square_Footage__c >= :SFmin and Square_Footage__c <= :SFmax '; 

            if( beds != '0' && SFminimum == 0 && SFmaximum == 0 && ILPminimum != 0 && ILPmaximum != 0)

                searchquery += 'and Initial_List_Price__c >= :ILPmin and Initial_List_Price__c <= :ILPmax ';

            if (beds >= '0' && SFminimum == 0 && SFmaximum == 0 && ILPminimum != 0 && ILPmaximum != 0)

                 searchquery += 'and Beds__c = '+beds+' and Initial_List_Price__c >= :ILPmin and Initial_List_Price__c <= :ILPmax ';

            if(beds >= '0' && SFminimum > 0 && SFmaximum > 0 && ILPminimum > 0 && ILPmaximum > 0)

                 searchquery += ' and Beds__c = '+beds+' and Square_Footage__c >= :SFmin and Square_Footage__c <= :SFmax and Initial_List_Price__c >= :ILPmin and Initial_List_Price__c <= :ILPmax ';


            if(beds != '0' && SFminimum == 0 && SFmaximum == 0 && ILPminimum > 0 && ILPmaximum == 0)

               searchquery += ' and Initial_List_Price__c <= :ILPmin ';


             if(beds != '0' && SFminimum == 0 && SFmaximum == 0 && ILPminimum == 0 && ILPmaximum > 0)

                 searchquery += ' and Initial_List_Price__c <= :ILPmax ';

             if(beds != '0' && SFminimum > 0 && SFmaximum == 0 && ILPminimum == 0 && ILPmaximum == 0)

                  searchquery += ' and Square_Footage__c <= :SFmin ';

             if(beds != '0' && SFminimum == 0 && SFmaximum > 0 && ILPminimum == 0 && ILPmaximum == 0)

                  searchquery += ' and Square_Footage__c <= :SFmax ';

              if(beds >= '0' && SFminimum == 0 && SFmaximum == 0 && ILPminimum > 0 && ILPmaximum == 0)

                 searchquery += ' and Beds__c = '+beds+' and Initial_List_Price__c >= :ILPmin ';

             if(beds >= '0' && SFminimum == 0 && SFmaximum == 0 && ILPminimum == 0 && ILPmaximum > 0)

                 searchquery += ' and Beds__c = '+beds+' and Initial_List_Price__c <= :ILPmax ';

               if(beds >= '0' && SFminimum > 0 && SFmaximum == 0 && ILPminimum == 0 && ILPmaximum == 0)

                  searchquery += ' and Beds__c = '+beds+' and Square_Footage__c >= :SFmin ';

                if(beds >= '0' && SFminimum == 0 && SFmaximum > 0 && ILPminimum == 0 && ILPmaximum == 0)



      searchquery += ' and Beds__c = '+beds+' and     Square_Footage__c <= :SFmax ';
      Cond = Database.query(searchquery);
      return Cond;
      }


     public PageReference processSelected() {

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

        //We will cycle through our list of cCondo and will check to see if the selected property is set to true, if it is we add the Condo to the selectedCondo list
        for(List<Condo__c> lstCondo: search()) {
        for(Condo__c cCondo: lstCondo) {
        if(cCondo.selected == true) {
            selectedCondo.add(cCondo);
        }
      }
    }
 }

  public void Reset(){ 
     beds = null;
     SFminimum = null;
     SFmaximum = null;
     ILPminimum = null;
     ILPmaximum = null;
     Cond.clear();

    }  
   }
3

I am just assuming.. You code will be like below.

search() may be returning list so yu need to iterate over Condo__c and in list you need to add cCondo like this way selectedCondo.add(cCondo);

public PageReference processSelected() {

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

    /*
       We will cycle through our list of cCondo and will check to see 
     if the selected property is set to true, 
     if it is we add the Condo to the selectedCondo list
     */
    for(Condo__c cCondo: search()) {
        if(cCondo.selected == true) {
            selectedCondo.add(cCondo);
        }
    }

Update

After looking into code sinse selected not a field just remove this line

for(List<Condo__c> lstCondo: search()) {
      for(Condo__c cCondo: lstCondo) {
        /*if(cCondo.selected == true) {*/
            selectedCondo.add(cCondo);
       /* }*/
      }
    }
  • I am getting below error "Compile Error: Incompatible element type List<Condo__c> for collection of Condo__c " – chaitanya Mar 31 '16 at 15:12
  • This is the error "Compile Error: Incompatible element type List<Condo__c> for collection of Condo__c " – chaitanya Mar 31 '16 at 15:13
  • @chaitanya check my updates... you need to update your for loop.. – Ratan Paul Mar 31 '16 at 15:15
  • Now i am getting this error "Compile Error: Invalid field selected for SObject Condo__c" – chaitanya Mar 31 '16 at 15:18
  • @chaitanya why you added selected in question ? – Ratan Paul Mar 31 '16 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.