Skip to content

Instantly share code, notes, and snippets.

@prasannadeshpande
prasannadeshpande / gist:fc8df805bfdc3d82afc62b74c28db438
Last active January 28, 2018 14:07
Datetime and BusinessHours1
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
@prasannadeshpande
prasannadeshpande / DatetimeOps1.cls
Last active January 28, 2018 14:20
Adding Business days to DateTime using BusniessHours
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;
}
@prasannadeshpande
prasannadeshpande / DateOps2.cls
Created January 28, 2018 14:26
Datetime operations
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;
@prasannadeshpande
prasannadeshpande / AttachmentTrigger.cls
Created January 28, 2018 14:32
TriggerOnAttachment
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!!');
}
}
}
@prasannadeshpande
prasannadeshpande / CurrencyFormat.js
Created January 28, 2018 14:37
Number to currency format in javascript
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)
@prasannadeshpande
prasannadeshpande / DeleteScheduleJobs.java
Created February 18, 2018 05:45
Delete all schedule jobs in an org.
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++)
@prasannadeshpande
prasannadeshpande / DownloadFilesFromRepo.ps1
Created June 18, 2020 15:54 — forked from zerotag/DownloadFilesFromRepo.ps1
PowerShell function to download files from a GitHub repository
function DownloadFilesFromRepo {
<#
.SYNOPSIS
This function retrieves the specified repository on GitHub to a local directory with authentication.
.DESCRIPTION
This function retrieves the specified repository on GitHub to a local directory with authentication, being a single file, a complete folder, or the entire repository.
.PARAMETER User