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
Amol DixitAmol Dixit 

After updation of records every time getting warning mail.

Hi,

 

I have very big problem. I have created an app in which I wants to chage the batch and plan of the resource. And accordingly I am creating tracker for them. But every time I update records It will give me Warning Mail, I dont know why?? Please help me out.

 

/*

Operation: /apex/changeplan

 

By user/organization: 00590000000v5ZR/00D90000000c8Oe

 

Caused the following Apex resource warnings:

 

Number of SOQL queries: 67 out of 100

 

(these emails can be disabled from the user detail page for this user)*/

 

 

Class  is as follows=

 

 

 

public class changePlanController{

    public Boolean getChkFlag() {
    if(chkFlag)
     chkFlag=true;
        return chkFlag;
    }
public Resource__c rso{get;set;}

    public String batch { get; set; }

    public String getBatch() {
        return null;
    }


    public changePlanController() {
        datevalue=new Special_Case__c();
        rso=new Resource__c();
        recalculateCounter=0;
        showChangeBlock=true;
        pcheck=false;
        bcheck=false;
        chkFlag=false;
    }
public boolean chkFlag{get;set;}    
public String assignTo1{get;set;}
public boolean showChangeBlock{get;set;}
public String checkRadio{get;set;}    
public String kt{get;set;}
public boolean showblock{get;set;}
public String BatchNameS{get;set;}
public boolean bcheck{get;set;}
public boolean pcheck{get;set;}
public String planname{get;set;}
public String planNameS{get;set;}
public Special_Case__c datevalue{get;set;}
public Integer chk{get;set;}
public String resourceName{get;set;}
public String lastTrainingBatch{get;set;}
public String lastTrainingPlan{get;set;}
public String pl{get;set;}
 public String unselectSub{get;set;}
public String batchname{get;set;}
public String ResName{get;set;}
Double hrs=0;
public Date startdate{get;set;}
Integer Year,Month,Day,objectdate,objectmonth,objectyear;
public String recievedId{get;set;}
public Special_Case__c splcase{get;set;}
public List<Special_Case__c> lst= new List<Special_Case__c>();
public Integer recalculateCounter{get;set;}
 public List<String> finalone{get;set;}
 public String trial{get;set;}
    public List<Resource__c> rs{get;set;}
    Double AllTotal=0;
    public String ras{get;set;}
 
    public List<SelectOption> getItems1() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Training Batch','Training Batch'));
        options.add(new SelectOption('Training Plan','Training Plan'));
         return options;
    }
    public void show(){
        showChangeBlock=true;
    }
    
    public void assign1(){
    showblock=true;
    trial='Hello';
        if(assignTo1=='Training Batch')
        {
            Bcheck=true;
            Pcheck=false;
        }
        else if(assignTo1=='Training Plan')
        {
            Pcheck=true;
            Bcheck=false;
        }
    }
    
    
    public PageReference saveNew()
    {
            resourceName=ras.substring(ras.indexOf('[')+1,ras.indexOf(']'));
            List<Special_Case__c> rt=new List<Special_Case__c>();
            rt=Database.query('select Id from Special_Case__c where EmpId__c=:resourceName');
            delete rt;
           for(Integer i=0;i<specialCase.size();i++)
            {
                Special_Case__c SC=new Special_Case__c();
                SC.New_Start_Date__c=specialCase[i].spCase.New_Start_Date__c;
                SC.New_End_Date__c=specialCase[i].spCase.New_End_Date__c;
                SC.New_Hours__c=specialCase[i].spCase.New_Hours__c;
                SC.EmpId__c=resourceName;
                insert SC;
            }


            return null;
    
    }
     public class text1 {
    public String Value { get; set; }
    public string flag {get;set;}
    public String Link{get;set;}
    public String sourceType{get;set;}
    public Special_Case__c spCase{get;set;}
    public text1()
    {
    spCase=new Special_Case__c();
    }
  }


  private List<text1> specialCase;

  public void setspecialCase(List<text1> items) {
    specialCase = items;
  }

 
  public List<text1> getspecialCase() {
    if(specialCase==null) {
      specialCase = new List<text1>();
      specialCase.add(new text1());
    }
    return specialCase;
  }
 
  public void addItem1() {
    specialCase.add(new text1());
  }
  public void deletemodule()
  {
  for(Integer i=specialCase.size()-1;i>=0;i--)
  {
  if(specialCase[i].flag=='true'){
  specialCase.remove(i);
  }
  }
    }
    
public Pagereference change(){
/*
Id d=Rso.Training_Batch__c;
List<Training_Batch__c> bchList=Database.query('select Name__c,Name from Training_Batch__c where id=:d');
BatchNameS=bchList[0].Name;
return null;
*/

reCalculateCounter=1;
MilestoneCalculation();
recalculateCounter=0;
ID lastid;
resourceName=ras.substring(ras.indexOf('[')+1,ras.indexOf(']'));
List<Resource_Tracker__c> rt=new List<Resource_Tracker__c>();
rt=Database.query('select Id from Resource_Tracker__c where Resource__r.Name=:resourceName');
delete rt;
   List<Resource__c> resource=new List<Resource__c>();
          resource= Database.query('select  Start_Date_on_SF__c,Training_Plan__r.Unselected__c,Training_Batch__r.Training_Plan__r.Unselected__c,Id,Name,Training_Batch__r.Name,Training_Batch__r.Training_Plan__r.Name,Training_Plan__r.Name,Training_Batch__c,Training_Plan__c from Resource__c where Name=:resourceName');
          lastid=resource[0].Id;
          resourceName=resource[0].Name;
        
          lastTrainingPlan=resource[0].Training_Batch__r.Training_Plan__r.Name;
          lastTrainingBatch=resource[0].Training_Batch__r.Name;
  BatchNameS=Rso.Training_Batch__c;
        if(bcheck==false)
      {
      Id d=Rso.Training_Plan__c;
      List<Training_Plan__c> plList=Database.query('select Name__c,Name from Training_Plan__c where id=:d');
      pl=plList[0].Name;
    
     List<Training_Plan__c> lst=new List<Training_Plan__c>();
     lst=Database.query('select Unselected__c,id from Training_Plan__c where Name=:pl');
     unselectSub=lst[0].Unselected__c;
     List<Resource__c> rlist=new List<Resource__c>();
     rlist=Database.query('select Training_Plan__c,Training_Batch__c,Training_Batch__r.Training_Plan__c from Resource__c where Name=:resourceName');
     rlist[0].Training_Batch__c=null;
      rlist[0].Training_plan__c=lst[0].id;
      
   /*  if(rlist[0].Training_Batch__c==null)
     rlist[0].Training_Plan__c=lst[0].id;
     else
     rlist[0].Training_Batch__r.Training_Plan__c=lst[0].id;*/
     upsert rlist;
       }
     else
     {
     Id d=Rso.Training_Batch__c;
     List<Training_Batch__c> bchList=Database.query('select Name__c,Name from Training_Batch__c where id=:d');
     BatchNameS=bchList[0].Name;
     List<Resource__c> rlist=new List<Resource__c>();
     rlist=Database.query('select Training_Plan__c,Training_Batch__c from Resource__c where Name=:resourceName');
     rlist[0].Training_Plan__c=null;
     rlist[0].Training_Batch__c=null;
     upsert rlist;
      List<Training_Batch__c> lst=new List<Training_Batch__c>();
     lst=Database.query('select Training_Plan__r.Name,Training_Plan__r.Unselected__c,Training_Plan__r.Name__c,id from Training_Batch__c where Name=:BatchNameS');
     unselectSub=lst[0].Training_Plan__r.Unselected__c;
     rlist[0].Training_batch__c=lst[0].id;
     upsert rlist;
     pl=lst[0].Training_Plan__r.Name;
     }
 
          finalone=new List<String>();
          if(unselectSub!=Null)
          finalone=unselectSub.split('/',100);
          
          List<Training_Plan_Module__c> mdle=new List<Training_Plan_Module__c>();
          mdle=Database.query('select Module__r.Name,Module__r.Name__c from Training_Plan_Module__c where Training_Plan__r.Name=:pl order by  Module__r.Name');

         for(Integer i=0;i<mdle.size();i++)
         {
         
             List<Submodule__c> submodule=new List<Submodule__c>();
             List<String> temp1=new List<String>();
             
             kt=mdle[i].Module__r.Name;
           
                submodule=Database.query('select Name,Hours__c,ID from Submodule__c where Module__r.Name=:kt');
                for(Integer j=0;j<submodule.size();j++)
                {
                    chk=0;
                    if(unselectSub!=Null)
                    {
                      for(Integer k=0;k<finalone.size();k++)
                     {
                           
                     if(finalone[k]==submodule[j].Name)
                     {
                             chk=1;
                          
                     }
                     }
                     }
                     
                         if(chk==0)
                         {
                                 Resource_Tracker__c Re=new Resource_Tracker__c();
                                 Re.Resource__c=lastid;           
                                 Re.Submodule__c=submodule[j].id;
                                 insert re;
                         }
                }
             }
             milestoneCalculation();

Pagereference ref=new Pagereference('/apex/changeplan');
ref.setredirect(true);
return ref;

}

}

Thank you

Amol Dixit

kiranmutturukiranmutturu

dont worry  u r code is about to reach the governing limit on number of quries that can be issued in call,...if you dont want these emails  then u need to go to the respective user detail page and disable the Send Apex Warning Emails checkbox