+ Start a Discussion
rajesh k 10rajesh k 10 

How give CRON Expression as Weekly Dynamically?

Hi,
       I gave 7 check boxes, like Sunday,Monday,Tuesday,wednesday,Thursday,Friday,Saturday(I gave these checkbox values as day1,day2.....day7).When i select checkbox ,based on selectd checkbox how to add cron Expression dynamically?

please help me.......
bob_buzzardbob_buzzard
As the cron trigger format is:

Seconds Minutes Hours Day_of_month Month Day_of_week optional_year

and Day_of_week is not optional, you'll need to work through the 7 properties and convert them to a string range. Something like:

String dayStr='';

dayStr+=(day1?',1':'');
dayStr+=(day2?',2':'');
dayStr+=(day3?',3':'');
dayStr+=(day4?',4':'');
dayStr+=(day5?',5':'');
dayStr+=(day6?',6':'');
dayStr+=(day7?',7':'');

if (dayStr.length()>0)
{
  // remove the leading comma
  dayStr=dayStr.substring(1);
}
else
{
   // default value when the user hasn't checked any values, required as the day of week isn't optional
   // could be '?' if day of month is specified
   dayStr='*';
}




bob_buzzardbob_buzzard
You don't need to add the selected checkboxes (sun to sat) - that is what the code I posted is setting up.  The picklist values can just be concatenated with the cron string,
rajesh k 10rajesh k 10
Hi sir,
           Here i was using if condition no problem

if(daySaturday == true||dayFriday == true||dayThursday == true||dayWednesday == true||dayTuesday == true||dayMonday == true||daySunday == true)
bob_buzzardbob_buzzard
So why did you post a question asking how to create a con string from those checkboxes?
bob_buzzardbob_buzzard
I don't have any code to do this I'm afraid - I'm happy to try to help if you get stuck. This is about the third post asking how to build the string from picklists which hasn't been answered with code, so maybe you should try developing the code yourself.
rajesh k 10rajesh k 10
Hi Sir,
              My Client requirement is Schedule a batch class from visualforce dynamically like salesforce schedule apex UI  thats way i am asking.Ui I created Like below


Title812180170
please help me sir


one frequency picklist field.I this picklist field values are Weekly,Monthly by day,Monthly by date and custom.When i select Weekly picklist value page rendered as Sunday,Monday.......Saturday checkboxes will be displayed.When i select Monthly by day picklist value page rendered as two picklists one is 1st,2nd,3rd,4th and last ,second picklist as Sunday,Monday.......Saturday  will be displayed.When i select Monthly by date picklist value page rendered as picklist as  1st,2nd,3rd,4th........31st and  last   will be displayed.When i select Custom value in picklist page rendered as  DayOfMonth(Textbox),Month:(Textbox),DayOfWeek:(Textbox),Year:(Textbox) .I gave Job name ,Startdate,Enddate and PreferredStartTime field as Hours(12AM,1AM....11PM),Minuts(00,01,02....59) and seconds(00,01,02....59).

NOTE:UI I designed how to perform backend operation based on my UI.

How to add Frequency as CRON Expresson Dynamically From visualforce page?

please help me..............
rajesh k 10rajesh k 10
Hi Sir,
             I will give my credentionals please help me............
bob_buzzardbob_buzzard
I'm not going to write the code for you - you'd have to pay quite a lot of money for me to do that.
rajesh k 10rajesh k 10
Hi sir,
            I joined as a Fresher our company.My salary only RS.7500
bob_buzzardbob_buzzard
I'm making the point that I provide Salesforce consultancy for a living, so you are asking me to write the code for your job for free.  That's not going to happen I'm afraid.  You'll need to make an attempt yourself - as you've seen, simply posting requests for someone to write the code for you doesn't work.
rajesh k 10rajesh k 10
Hi sir,
           I am only one of the developer of our company.I ask to any one also not there thats why i am asking. I will try  thank you for replys Sir..........
rajesh k 10rajesh k 10
Hi,
         Above code working perfectly,

How to add selectoption values to CRON Expression Dynamically?
Hi,
             I have picklists as like
<apex:selectList title="" value="{!monthDayNumber}" size="1" multiselect="false">
                                            <apex:selectOptions value="{!monthDayNumberOptions}"/>
                                       </apex:selectList>
                                      <apex:selectList title="" value="{!monthDay}" size="1" multiselect="false">
                                            <apex:selectOptions value="{!monthDayOptions}"/>
                                       </apex:selectList>

In controller As
...........................

public String monthDayNumber{get;set;}
public String monthDay{get; set;}

   public List<selectOption> getMonthDayOptions() {

   List<selectOption> option=new List<selectOption>();
      
    option.add(new selectOption('Sunday','Sunday'));
    option.add(new selectOption('Monday','Monday'));
    option.add(new selectOption('Tuesday','Tuesday'));
    option.add(new selectOption('Wednesday','Wednesday'));
    option.add(new selectOption('Thursday','Thursday'));
    option.add(new selectOption('Friday','Friday'));
    option.add(new SelectOption('Saturday','Saturday'));
 
        return option;
    }
public List<selectOption> getMonthDayNumberOptions() {
  
    List<selectOption> option=new List<selectOption>();
     option.add(new selectOption('1st','1st'));
     option.add(new selectOption('2nd','2nd'));
     option.add(new selectOption('3rd','3rd'));
     option.add(new selectOption('4th','4th'));
     option.add(new selectOption('Last','Last'));
 
        return option;
    }

How to add these Selectoptions to CRON Expression Dynamically ?///This only sir i don't ask again I will complete my own.

please help me............
Faiza Naz 10Faiza Naz 10
May be its too late to answer your question now. but you can get help from below link.This link explains with code snippets
http://faizanaz90.blogspot.com/2016/03/apex-creating-cron-expression.html