1

I have Custom Object Scheduler__c which contains fields StartTime,EndTime,T9,T930,T10,T1030,T11,T1130,T12,T1230..........T17(5PM).T9 to T17 are time slots for 30 minutes and these are Number DataType holds value 0 or 1.

I created a VF page and it contains 2 SelectList and values for these lists are 9,9:30,10,10:30.........5:00.When user selects 9:30(SelectList)(Value is '2') and 12:00(Another SelectList Value is '7') the values i need to store for T930,T10,T1030,T11,T1130,T12 is 1 and remaining field values should be 0.How do i achieve this.

Please Help.

1

Seems like you could just brute force your way through with Apex.

integer startSelect = 2; // User has selected 9:30 in the first SelectList
integer stopSelect = 7; // User has selected 12:00 in the second SelectList

Scheduler__c sch = new Scheduler__c();
sch.T9__c = (startSelect <= 1 && stopSelect >= 1)?1:0;
sch.T930__c = (startSelect <= 2 && stopSelect >= 2)?1:0;
sch.T1030__c = (startSelect <= 3 && stopSelect >= 3)?1:0;
// ...
sch.T12__c = (startSelect <= 7 && stopSelect >= 7)?1:0;
// ...

Personally, I'd make these fields Boolean/checkboxes rather than numbers. However, I don't know what else you are doing with them.

  • Its working fine thank you @Daniel Ballinger .But so many if condition,is there any other way do it simple..? – NullReferenceException May 6 '14 at 10:43
  • You could create two DateTime fields to hold the values and ignore the Date component of them. Then you would only need to set two values. – Daniel Ballinger May 6 '14 at 19:33
  • Or create a method that takes the startSelect, stopSelect and threshold integer as parameters and applies the logic in one place. – Daniel Ballinger May 6 '14 at 19:35
  • You could create two DateTime fields to hold the values and ignore the Date component of them. Then you would only need to set two values.How can i do this...?the second approach i did. – NullReferenceException May 7 '14 at 6:17
  • Exactly that. Make two custom fields with the DataTime data type. One for the start time and one for the stop time. Then set the time component of each of these as required by the user selected start and stop date. Set the date component to some fixed value and ignore it. – Daniel Ballinger May 7 '14 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.