Instantly share code, notes, and snippets.

View DeleteScheduleJobs.java
List<CronTrigger> listCronTrigger = [select Id, CronExpression, EndTime, NextFireTime, OwnerId,
PreviousFireTime, StartTime, State, TimesTriggered, TimeZoneSidKey from CronTrigger
where State = 'Waiting' or State='Running'];
System.debug('No of jobs: '+listCronTrigger.size());
If (listCronTrigger.size() > 0)
{
for (Integer i = 0; i < listCronTrigger.size(); i++)
View CurrencyFormat.js
function FormatToCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents < 10)
View AttachmentTrigger.cls
trigger AttachmentTrigger on Attachment (before insert) {
set<String> setExtNotAllowed = new set<String> {'exe','dll'};
for (Attachment attachment :Trigger.new) {
String strFilename = attachment.Name.toLowerCase();
List<String> parts = strFilename.splitByCharacterType();
if(setExtNotAllowed.Contains(parts[parts.size()-1])) {
attachment.addError('File with extension exe or dll could not be attached!!');
}
}
}
View DateOps2.cls
global Datetime addBussinessDays(Datetime startDate, Integer iDays)
{
Datetime endDate = startDate.addDays(iDays);
Integer iOffDays = daysOff(startDate,endDate);
return endDate.addDays(iOffDays);
}
global Integer daysOff(Datetime sdate, Datetime edate)
{
Integer iCount = 0;
View DatetimeOps1.cls
public static Datetime addBusinessDays(Datetime startDate, Integer numberOfDays, id busniesshourId)
{
Integer count = 0;
while (count < days) {
startDate = startDate.addDays(1);
if (BusinessHours.isWithin(businesshourId, startDate))
count++;
}
return startDate;
}
View gist:fc8df805bfdc3d82afc62b74c28db438
Long interval = 24 * 60 * 60 * 1000;
h m s ms
Datetime dt = DateTime.newInstance(2017, 12, 18, 10,0,0);
System.debug('Date :' + dt.format());
Long interval = (24 * 60 * 60 * 1000);
Datetime newdt = BusinessHours.add(bh.Id, dt, interval);
System.debug('After adding 1 day :' + newdt.format());
//OUTPUT
22:12:52:003 USER_DEBUG [3]|DEBUG|Date :12/18/2017 10:00 AM