+ Start a Discussion
cml9cml9 

Compile Error: Loop condition must be of type Boolean

public class wrapperExample2 {

  List <Product_Entry__c> ProdList=new List<Product_Entry__c>();
  List <wrapper> lstw =new List<wrapper>();
  
  public List<wrapper> getlstWrapperString() 
  
      { 
              ProdList=[select name,Price__c from Product_Entry__c];
               for (integer i=0; ProdList.size();i++) 
                      {
                  lstw.add(new wrapper(ProdList[i].name,ProdList[i].Price__c));
                      }
              
                      return lstw;
        }
                      
 public Class wrapper {  
     public string name {get;set;}
     public decimal price {get;set;}
     public wrapper(string Name,decimal Price) 
             {
             this.Name = Name;
             this.Price = Price; 
             }
    
     }
  }

 
Best Answer chosen by cml9
Amit Chaudhary 8Amit Chaudhary 8
Yes you can update your loop like below

Example 1:-
public List<wrapper> getlstWrapperString() 
		{ 
				ProdList=[select name,Price__c from Product_Entry__c];
				for (integer i=0; ProdList.size() > i ; i++)  
                {
					lstw.add(new wrapper(ProdList[i].name,ProdList[i].Price__c));
                }
              
                      return lstw;
        }

Example 2:-
public List<wrapper> getlstWrapperString() 
{ 
	ProdList=[select name,Price__c from Product_Entry__c];
	for (Product_Entry__c pe : ProdList)   
	{
		lstw.add(new wrapper( pe.name, pe.Price__c ) );
	}              
	return lstw;
}
Your final code should be like below
public class wrapperExample2 {

  List <Product_Entry__c> ProdList=new List<Product_Entry__c>();
  List <wrapper> lstw =new List<wrapper>();
  
	public List<wrapper> getlstWrapperString() 
	{ 
		ProdList=[select name,Price__c from Product_Entry__c];
		for (Product_Entry__c pe : ProdList)   
		{
			lstw.add(new wrapper( pe.name, pe.Price__c ) );
		}              
		return lstw;
	}
                      
	public Class wrapper 
	{  
		public string name {get;set;}
		public decimal price {get;set;}
		public wrapper(string Name,decimal Price) 
		{
			this.Name = Name;
			this.Price = Price; 
		}
    
    }
}



 

All Answers

Ishwar ShindeIshwar Shinde
Please update code as follows - 
 
public class wrapperExample2 {

  List <Product_Entry__c> ProdList=new List<Product_Entry__c>();
  List <wrapper> lstw =new List<wrapper>();
  
  public List<wrapper> getlstWrapperString() 
  
      { 
              ProdList=[select name,Price__c from Product_Entry__c];
					for (integer i=0; ProdList.size()-1>i ; i++)  
                    {
						lstw.add(new wrapper(ProdList[i].name,ProdList[i].Price__c));
                    }
              
                      return lstw;
        }
                      
 public Class wrapper {  
     public string name {get;set;}
     public decimal price {get;set;}
     public wrapper(string Name,decimal Price) 
             {
             this.Name = Name;
             this.Price = Price; 
             }
    
     }
  }

It will break for loop after iteration of list.
Amit Chaudhary 8Amit Chaudhary 8
Yes you can update your loop like below

Example 1:-
public List<wrapper> getlstWrapperString() 
		{ 
				ProdList=[select name,Price__c from Product_Entry__c];
				for (integer i=0; ProdList.size() > i ; i++)  
                {
					lstw.add(new wrapper(ProdList[i].name,ProdList[i].Price__c));
                }
              
                      return lstw;
        }

Example 2:-
public List<wrapper> getlstWrapperString() 
{ 
	ProdList=[select name,Price__c from Product_Entry__c];
	for (Product_Entry__c pe : ProdList)   
	{
		lstw.add(new wrapper( pe.name, pe.Price__c ) );
	}              
	return lstw;
}
Your final code should be like below
public class wrapperExample2 {

  List <Product_Entry__c> ProdList=new List<Product_Entry__c>();
  List <wrapper> lstw =new List<wrapper>();
  
	public List<wrapper> getlstWrapperString() 
	{ 
		ProdList=[select name,Price__c from Product_Entry__c];
		for (Product_Entry__c pe : ProdList)   
		{
			lstw.add(new wrapper( pe.name, pe.Price__c ) );
		}              
		return lstw;
	}
                      
	public Class wrapper 
	{  
		public string name {get;set;}
		public decimal price {get;set;}
		public wrapper(string Name,decimal Price) 
		{
			this.Name = Name;
			this.Price = Price; 
		}
    
    }
}



 
This was selected as the best answer
Jasveer SinghJasveer Singh
Hi cml9

please correct this line your code is right
 
for (integer i=0; i<ProdList.size();i++)

Thanks & Regards
Jasveer Singh
 
cml9cml9
Everyone thank you for the Help! it now working and I was using Amit Chaudhary 8 code. Now this brings me to other problem and hope that you guys can help me with this.

Please see https://developer.salesforce.com/forums/ForumsMain?id=906F0000000QtfwIAC.