function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mohit tripathimohit tripathi 

Controller extension- unable to mark checkbox as true

Hi Team,

So I am trying to update a checkbox field as true or false based on quarter but unable to do so.
Can anybody please check this code and tell me where i am wring?

public class Customerecommendedcontroller {


Set<Integer> Q1 = new Set<Integer>{1,2,3};
 Set<Integer> Q2 = new Set<Integer>{4,5,6};
Set<Integer> Q3 = new Set<Integer>{7,8,9};
 Set<Integer> Q4 = new Set<Integer>{10,11,12};
public Account ac;
  integer cMonth= date.today().month();
  Public List<recommended_Steps__c> totestList{get;set;}
  public List<recommended_Steps__c> lstForUpdate = new list<recommended_Steps__c>();
  public Customerecommendedcontroller(ApexPages.StandardController controller) {
       ac=(Account)controller.getrecord();
   }
   public  list<recommended_Steps__c> recomn{
 get{
 totestList = [select  Check__c, Account__c,Quarter__c,Due_date__c,Current_Quarter__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];
 for(recommended_Steps__c rc : totestList ){
 if(Q1.contains(cMonth))
{
    rc.Current_Quarter__c = 'Q1';
    if(rc.Quarter__c == rc.Current_Quarter__c){
      rc.Check__c = true ;

    }
    else{
    rc.Check__c= false;
    }
   
  }
  if(Q2.contains(cMonth))
{
    rc.Current_Quarter__c = 'Q2';
    if(rc.Quarter__c== rc.Current_Quarter__c){
      rc.Check__c = true ;

    }
    else{
    rc.Check__c= false;
    }

   
  }
if(Q3.contains(cMonth))
{
    rc.Current_Quarter__c = 'Q3';
    if(rc.Quarter__c== rc.Current_Quarter__c){
      rc.Check__c = true ;

    }
    else{
    rc.Check__c= false;
    }

   
  }
if(Q4.contains(cMonth))
{
    rc.Current_Quarter__c = 'Q4';
    if(rc.Current_Quarter__c == rc.Quarter__c){
      rc.Check__c = true ;

    }
    else{
    rc.Check__c= false;
    }

   
  }

lstForUpdate.add(rc);

 }
 update totestList ;
 update lstForUpdate;
  return totestList ;
 }
 
 
 set{}
 }
 }
Ajay K DubediAjay K Dubedi
Hi Mohit, 

Try this code, also I have inserted debugs at certain sections in the code, Please check the debug log, and see if you are able to fetch those values or not.
 
Set<Integer> Q1 = new Set<Integer>{1,2,3};
Set<Integer> Q2 = new Set<Integer>{4,5,6};
Set<Integer> Q3 = new Set<Integer>{7,8,9};
Set<Integer> Q4 = new Set<Integer>{10,11,12};
public Account ac;
  integer cMonth= date.today().month();
  Public List<recommended_Steps__c> totestList{get;set;}
  public List<recommended_Steps__c> lstForUpdate = new list<recommended_Steps__c>();
  public Customerecommendedcontroller(ApexPages.StandardController controller) {
       ac=(Account)controller.getrecord();
   }
 public  list<recommended_Steps__c> recomn{
 get{
 totestList = [select  Check__c, Account__c,Quarter__c,Due_date__c,Current_Quarter__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];
 system.debug('>>>>totestList'+totestList);
 if(totestList.size()>0){
 for(recommended_Steps__c rc : totestList ){
 if(Q1.contains(cMonth))
{
    rc.Current_Quarter__c = 'Q1';
    if(rc.Quarter__c == rc.Current_Quarter__c){
      rc.Check__c = true ;
    }
}
  if(Q2.contains(cMonth))
{
    rc.Current_Quarter__c = 'Q2';
    if(rc.Quarter__c== rc.Current_Quarter__c){
      rc.Check__c = true ;
    }
  }
if(Q3.contains(cMonth))
{
    rc.Current_Quarter__c = 'Q3';
    if(rc.Quarter__c== rc.Current_Quarter__c){
      rc.Check__c = true ;
    }
  }
if(Q4.contains(cMonth))
{
    rc.Current_Quarter__c = 'Q4';
    if(rc.Current_Quarter__c == rc.Quarter__c){
      rc.Check__c = true ;
    }
  }
lstForUpdate.add(rc);
}
system.debug('>>>>>>lstForUpdate'+lstForUpdate);
system.debu('>>>>>>>totestList'+totestList);
if(lstForUpdate.size()>0){
 insert lstForUpdate;
}
 update totestList ;
 return totestList ;
 }
 }
 set{}
 }
 }

Thanks,
Ajay