You need to sign in to do that
Don't have an account?
Raveendra Vaka
How to split the Date and creating more than 14days Event record in SFDC?
How to create more than 14 days Event record?
EX: i want run 6 months continually, but Salesforce allow max 14day,so how to split the date and creating multipule events
Any body help me...
Thanks,
EX: i want run 6 months continually, but Salesforce allow max 14day,so how to split the date and creating multipule events
Any body help me...
Thanks,
public class EventCreator {
Date startDate;
Date endDate;
List<Event> newEventList;
public EventCreator(Date srtDate, Date eDate) {
try {
startDate = srtDate;
endDate = eDate;
newEventList = new List<Event>();
createEvents();
insert newEventList;
}catch(exception e) {
}
}
public void createEvents() {
while(startDate <= endDate) {
createEvent(startDate);
startDate = startDate.addDays(15);
system.debug(' == startDate1 == ' + startDate);
}
}
@TestVisible
private void createEvent(Date startDate) {
Event newEvent = new Event();
newEvent.Subject = 'Sf Discussion Meet up';
newEvent.StartDatetime = startDate;
if( startDate.daysBetween(endDate) >= 14){
newEvent.EndDateTime = startDate.addDays(14);
} else {
newEvent.EndDateTime = startDate.addDays(startDate.daysBetween(endDate));
}
newEventList.add(newEvent);
}
}
How to split the Date?
Suppose I given StartDate(Mar/27/2015) and EndDate(Mar/27/2016) duration is 1 year. So, how to split 1 year and create event records every 14day...
Ex: Like 365/14=26 Events
1-14(1st Event), 15-28(2nd Event)…
I hope you understand my logic?
you can get Month as integer after passing string, we need to implement the logic for that.
a small change in the logic will work.
public static Map<String, Integer> monthMap = new Map<String, Integer>{ 'Jan'=>1,
'Feb'=>2,
'Mar'=>3,
'Apr'=>4,
'May'=>5,
'Jun'=>6,
'July'=>7,
'Aug'=>8,
'Sep'=>9,
'Oct'=>10,
'Nov'=>11,
'Dec'=>12};
// Accepting String parameters instead of Date
public EventCreator(String srtDate, String eDate) {
List<String> srtMonth = srtDate.split('/');
List<String> eMonth = eDate.split('/');
startDate = Date.newinstance(Integer.valueOf(srtMonth[2]), monthMap.get(srtMonth[0]), Integer.valueOf(srtMonth[1]));
endDate = Date.newinstance(Integer.valueOf(eMonth[2]), monthMap.get(eMonth[0]), Integer.valueOf(eMonth[1]));
system.debug(' StartDate => ' + startDate + ' EndDate => ' + endDate);
newEventList = new List<Event>();
createEvents();
insert newEventList;
}