+ Start a Discussion
mohit tripathimohit tripathi 

compiler error in controller

Hi Guys,

 

Can anybody please tell me why I am getting this error:

Error: Customerecommendedcontroller Compile Error: Expecting '}' but was: 'for' at line 14 column 1

Controlller is as follows-

public class Customerecommendedcontroller {

 public Account ac;
 integer Quarter = Date.Today().Month()/3;
Public List<recommended_Steps__c> totestList{
get{
List<recommended_Steps__c> totestList= [select Quarter__c from recommended_Steps__c where Account__r.id = :ac.id];
retrun totalList;
}
set{}

}

for(recommended_Steps__c rc : totestList )
{
if(Quarter == Quarter__c){
Check__c = true;
}
else

Check__c = false;

 }
 update rc;
 totestList.add(rc);
 
 public list<recommended_Steps__c> recom{
 get{
 List<recommended_Steps__c> recom = [select id,     Account__c,Due_date__c,Steps_to_taken__c,Subject__c,recommended_Steps__c.Sprint__r.End_Date__c  from recommended_Steps__c where Account__r.id = :ac.id and Check__c= true];
 return recom;
 }
 set{
 }
 
 
 }
 
 

    public Customerecommendedcontroller(ApexPages.StandardController controller) {
       ac=(Account)controller.getrecord();
    }

}

Thanks in Advance :)

Best Answer chosen by mohit tripathi
piyush_sonipiyush_soni
hi mohit, yes there is lot's of syntax error in your apex code, i have refine your code use below code. and i recommended that start learning apex from trailhead and then you can start from apex developer guide
https://trailhead.salesforce.com/en/modules/apex_database/units/apex_database_intro

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_reference.htm
public class Customerecommendedcontroller {

 public Account ac;
 integer Quarter = Date.Today().Month()/3;
 Public List<recommended_Steps__c> totestList{get;set;}
 public List<recommended_Steps__c> lstForUpdate = new List<recommended_Steps__c>();
 public list<recommended_Steps__c> recom{get;set;}
 

    public Customerecommendedcontroller(ApexPages.StandardController controller) {
       
	   ac =(Account)controller.getrecord();
	    
	   totestList = [select Quarter__c,Check__c from recommended_Steps__c where Account__r.id = :ac.id];
   
      for(recommended_Steps__c rc : totestList ){
        if(Quarter == rc.Quarter__c){
         rc.Check__c = true;
      }else{
         rc.Check__c = false;	 
      }
        lstForUpdate.add(rc);
     }

   if(lstForUpdate.size() > 0){
	  update lstForUpdate;
   }
  
 }

}

i hope it helps you.
  Let me inform if it helps you and kindly mark it best answer if it helps you
thanks

All Answers

mohit tripathimohit tripathi
Hi Piyush,


Thanks for the quick reply.
I have made the changes but still getting the same error.

updated controller-

public class Customerecommendedcontroller {

 public Account ac;
 integer Quarter = Date.Today().Month()/3;
Public List<recommended_Steps__c> totestList{
get{
List<recommended_Steps__c> totestList= [select Quarter__c from recommended_Steps__c where Account__r.id = :ac.id];
retrun totalList;
}
set{}

}

for(recommended_Steps__c rc : totestList )
{
if(Quarter == rc.Quarter__c){
rc.Check__c = true;
}
else

rc.Check__c = false;

 }
 update rc;
 totestList.add(rc);
 
 public list<recommended_Steps__c> recom{
 get{
 List<recommended_Steps__c> recom = [select id,     Account__c,Due_date__c,Steps_to_taken__c,Subject__c,recommended_Steps__c.Sprint__r.End_Date__c  from recommended_Steps__c where Account__r.id = :ac.id and Check__c= true];
 return recom;
 }
 set{
 }
 
 
 }
 
 

    public Customerecommendedcontroller(ApexPages.StandardController controller) {
       ac=(Account)controller.getrecord();
    }

}

error-
Error: Customerecommendedcontroller Compile Error: Expecting '}' but was: 'for' at line 14 column 1

Thanks a lot.
mohit tripathimohit tripathi
Hi Pratik,

Tried your optimized code.
public class Customerecommendedcontroller {

 public Account ac;
  integer Quarter = Date.Today().Month()/3;
  Public List<recommended_Steps__c> totestList{
  get{
     List<recommended_Steps__c> totestList= [select Quarter__c from recommended_Steps__c where Account__r.id = :ac.id];
     retrun totalList;
    }
   set{}
}

  public List<recommended_Steps__c> lstForUpdate = new List<recommended_Steps__c>();
 

for(recommended_Steps__c rc : totestList ){
  if(Quarter == rc.Quarter__c){
     rc.Check__c = true;
  }else{
   rc.Check__c = false; 
 }
 lstForUpdate.add(rc);
}

if(lstForUpdate.size() > 0){
    update lstForUpdate;
}

 
 public list<recommended_Steps__c> recom{
 get{
 List<recommended_Steps__c> recom = [select id,     Account__c,Due_date__c,Steps_to_taken__c,Subject__c,recommended_Steps__c.Sprint__r.End_Date__c  from recommended_Steps__c where Account__r.id = :ac.id and Check__c= true];
 return recom;
 }
 set{}
 }
 
 

    public Customerecommendedcontroller(ApexPages.StandardController controller) {
       ac=(Account)controller.getrecord();
    }

}

But still getting this error-

Error: Customerecommendedcontroller Compile Error: Expecting '}' but was: 'for' at line 16 column 1

I dont know what we are missing.


Thanks a lot.
piyush_sonipiyush_soni
hi mohit, yes there is lot's of syntax error in your apex code, i have refine your code use below code. and i recommended that start learning apex from trailhead and then you can start from apex developer guide
https://trailhead.salesforce.com/en/modules/apex_database/units/apex_database_intro

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_reference.htm
public class Customerecommendedcontroller {

 public Account ac;
 integer Quarter = Date.Today().Month()/3;
 Public List<recommended_Steps__c> totestList{get;set;}
 public List<recommended_Steps__c> lstForUpdate = new List<recommended_Steps__c>();
 public list<recommended_Steps__c> recom{get;set;}
 

    public Customerecommendedcontroller(ApexPages.StandardController controller) {
       
	   ac =(Account)controller.getrecord();
	    
	   totestList = [select Quarter__c,Check__c from recommended_Steps__c where Account__r.id = :ac.id];
   
      for(recommended_Steps__c rc : totestList ){
        if(Quarter == rc.Quarter__c){
         rc.Check__c = true;
      }else{
         rc.Check__c = false;	 
      }
        lstForUpdate.add(rc);
     }

   if(lstForUpdate.size() > 0){
	  update lstForUpdate;
   }
  
 }

}

i hope it helps you.
  Let me inform if it helps you and kindly mark it best answer if it helps you
thanks
This was selected as the best answer
mohit tripathimohit tripathi
I Piyush,

Will surely try to improve and learn.
Thanks for your support.
mohit tripathimohit tripathi
Piyush,

On my Detail page I am getting an error where I am displaying VF page.


Content cannot be displayed: DML currently not allowed

Can you please suggest something?

Thanks
piyush_sonipiyush_soni
hi mohit, yest you get this error because you can not use update (DML) in class Constructor, as i say there is lot's of syntax in your code so complete basic apex learning and then try again also please put your complete requirement with details as a new query question so other developers and experts take a look into this and helps you to resolve your query

Thank you