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
Karthikeyan KannanKarthikeyan Kannan 

How Can I delete a PageBlockTable column if the Date is Passed ?

Hi ,
      I have a Inline Section and it has Start Date AND End date row with multiple column, Now I want to delete the Column if The End Date is Passed, Can any one help me how to achieve this with the Scheduler class.?
rohitsfdcrohitsfdc
Hello Karthikeyan,
Do you wan to delete this in the database or dont want to display it in the vf page?


Karthikeyan KannanKarthikeyan Kannan
Hi Rohit,
 I am entering multiple rows with the Start date and End date, If the End date is passed that whole row [Start Date & End Date] Should be Deleted Permanently from the Database.
rohitsfdcrohitsfdc
try the code below:

global class TestScheduledApex implements Schedulable {

   global void execute(SchedulableContext ctx) {
		list<objectapiname> allrecodstodelete = [select id from objectapiname where enddate<Date.today()];
		if(allrecodstodelete.size()>0)
		
		try{
		delete allrecodstodelete;
		}catch(DMLException e){
		system.debug(e);		}
   }   
}

Karthikeyan KannanKarthikeyan Kannan
Hi Rohit,
I have posted my codes here Kindly check and help me,
===========Controller============
public class InlineTechnicianController
{
   public boolean isEdit {get;set;}
    public boolean flag {get;set;}
    public boolean isSaved {get;set;}
    public String selectedValue{get;set;}
    public Integer RemoveRow {get;set;}
public InlineTechnicianController(ApexPages.StandardController controller)
    {
        flag=false;
        isEdit=false;
        isSaved = true;
}

public class TechnicianWrapper
    {
        public String StartDate{get;set;}
        public String EndDate{get;set;}
        public String Technician{get; set;}
}       
      Engineer__c newList = [select Id,Start_Date_Long__c,End_Date_Long__c from Engineer__c where Id=:ApexPages.currentPage().getParameters().get('id')];
        public List<TechnicianWrapper> techList = new List<TechnicianWrapper>();
       public List<TechnicianWrapper> getTechnician() // For populating Dates public List<YourWrapperClass> yourWrapperClassVar{get;set;}
         {   
               if(techList.isEmpty())//Avoids list getting repopulated with same Values over and over again.
        {         
          if(newList.Start_Date_Long__c!=null && newList!=null)// Only if fields from which the data is getting filled are populated.
            {
                List<String> sdate,edate;
                sdate= newList.Start_Date_Long__c.split(';',-1);
                
                if(newList.End_Date_Long__c!=null)
                    edate = newList.End_Date_Long__c.split(';',-1);
                                                                  
                for(Integer iterator=0;iterator<sdate.size();iterator++)
                {
                    TechnicianWrapper instance = new TechnicianWrapper();
                                      
                    if(sdate!=null)
                    instance.StartDate = sdate[iterator];
                    if(edate!=null)
                    instance.EndDate = edate[iterator];
                                       
                   techList.add(instance);   
                }
            }
        }
         return techList;
       
    }
    public PageReference editTechDate()
    {
        isEdit=true;
        isSaved = false;
        return null;
    }
    public PageReference addTechDate()
    {
       
       TechnicianWrapper instance = new TechnicianWrapper();
       techList.add(instance);
       return null;   
    }
    public PageReference saveTechDate()
    {
        Boolean isError=false;
        Boolean isError3=false;
        Boolean isError4=false;
        Boolean isError5=false;
       
        String sdt='', edt='';
             
     /* if(flag)
        {
          techList = new List<TechnicianWrapper>();
        }*/
      
        for(TechnicianWrapper iterator:techList)
        { 
                
            if(sdt=='')
            {
                sdt = iterator.StartDate;
                edt = iterator.EndDate;
               }
            else
            {
                sdt = sdt+';'+iterator.StartDate;
                edt = edt+';'+iterator.EndDate;
               
            }
             if(iterator.startDate=='')
             {
                isError3 = true;
            }
            
            if(iterator.StartDate!='' && iterator.EndDate=='')
            {
                isError4 = true;
            }
             if(iterator.StartDate=='' && iterator.EndDate!='')
            {
                isError5 = true;
            }
           
        }
        Engineer__c newList= [select Id,Start_Date_Long__c,End_Date_Long__c from Engineer__c
                            where Id=:ApexPages.currentPage().getParameters().get('id')];
       
         newList.Start_Date_Long__c = sdt;
         newList.End_Date_Long__c = edt;
      
       
         if(isError)
        {
            ApexPages.Message myMsg=new ApexPages.Message(ApexPages.Severity.Error, 'Pass and Fail cannot be selected at the same time.');
            ApexPages.addMessage(myMsg);
        }
        else if(isError3)
        {
            ApexPages.Message myMsg=new ApexPages.Message(ApexPages.Severity.Error, 'Cannot save without Start & End Dates. ');
            ApexPages.addMessage(myMsg);
        }
        else if(isError4)
        {
            ApexPages.Message myMsg=new ApexPages.Message(ApexPages.Severity.Error, 'Cannot save without End Date');
            ApexPages.addMessage(myMsg);
        }
         else if(isError5)
        {
            ApexPages.Message myMsg=new ApexPages.Message(ApexPages.Severity.Error, 'Cannot save without Start Date');
            ApexPages.addMessage(myMsg);
        }
        else
        {
       
        //try{
                        
                update newList;
               
                Engineer__c newList2= [select Id,Start_Date_Long__c,End_Date_Long__c from Engineer__c
                        where Id=:ApexPages.currentPage().getParameters().get('id') limit 1];
        }
        isEdit=false;
        isSaved = true;
    }
    return null;
    }
}

==================PAGE==================
<apex:page controller="InlineTechnicianController" id="mypage" sidebar="false">
    <apex:form id="form1" >
    <apex:pageBlock id="pgBlok" rendered="{!isSaved}">
  <apex:pageblockButtons location="top">
  <apex:commandButton value="Edit Dates" action="{!editTechDate}" reRender="form1"/>
      </apex:pageblockButtons>
         <apex:pageBlockSection columns="1">
                <apex:pageBlockTable value="{!Technician}" var="tc">

                    <apex:column headerValue="StartDate"><apex:outputText value="{!tc.StartDate}" ></apex:outputText></apex:column>
                    <apex:column headerValue="EndDate"><apex:outputText value="{!tc.EndDate}"></apex:outputText></apex:column>
                                      
                </apex:pageBlockTable>
         </apex:pageBlockSection>
       
      </apex:pageBlock>
    <apex:pageBlock id="pgBlok1" rendered="{!isEdit}">
  <apex:pageblockButtons location="top">
    <apex:commandButton value="Add Row" action="{!addTechDate}" reRender="form1"/>
    <apex:commandButton value="Save Row" action="{!saveTechDate}" reRender="form1"/>
     </apex:pageblockButtons>
     <!-- apex:variable value="{!0}" var="RemoveValue" / -->
         <apex:pageBlockSection columns="1">
                <apex:pageBlockTable value="{!Technician}" var="tc">

                    <apex:column headerValue="StartDate"><apex:inputText value="{!tc.StartDate}" size="10" id="demo" onfocus="DatePicker.pickDate(false, this , false);"></apex:inputText></apex:column>
                    <apex:column headerValue="EndDate"><apex:inputText value="{!tc.EndDate}" size="10" id="demo1" onfocus="DatePicker.pickDate(false, this , false);"></apex:inputText></apex:column>
                   
                    <!--<apex:column >
                    <apex:commandLink value="Remove row" action="{!doRemove}" rendered="{!RemoveValue>=0}" reRender="form1">
                    <apex:param value="{!RemoveValue}" name="index" />
                    </apex:commandLink>
                    <apex:variable var="RemoveValue" value="{!RemoveValue+1}"/>
                    </apex:column>
                    -->
                </apex:pageBlockTable>
         </apex:pageBlockSection>
       
      </apex:pageBlock>  
      
    </apex:form>
</apex:page>


========================= SCHEDULER===========================

global class TestRecordManager implements Schedulable{
    global void execute(SchedulableContext sc){
    try{
List<Technician_Orders__c> TechnicianDate =[SELECT Id,name,Start_Date_Long__c,End_Date_Long__c  FROM Technician_Orders__c];
        if(TechnicianDate.End_Date_Long__c !=NULL ){
           String Date;
           Date=TechnicianDate.End_Date_Long__c;
           List<String>newDate=Date.split(';', 0);
           for(String s :newDate){
                 if(s.contains(Today())){
                 Delete s;
                 }
               }
           }
catch(Exception e) {
      String msg=e.getMessage();
      }
    }
}