Skip to content

Instantly share code, notes, and snippets.

@gbutt
gbutt / create-diff-package.sh
Created January 24, 2023 01:09
Create Diff Package - Salesforce
#!/bin/bash
# this function will only rsync files and folders once
rsync_unique () {
local syncpath=$1
if [[ -d ${syncpath} ]]; then
if [[ " ${RSYNED_DIRS[@]} " =~ " ${syncpath} " ]]; then
echo "already rsyned ${syncpath}" &> /dev/null
else
@gbutt
gbutt / EmailBuilder.cls
Last active April 21, 2021 03:57
An email builder for salesforce apex
public virtual class EmailBuilder {
private static final Logger log = LoggerFactory.getInstance(EmailBuilder.class);
@TestVisible
public Messaging.SingleEmailMessage email {
get;
private set;
}
public EmailBuilder() {
@gbutt
gbutt / SchedulableWrapper.cls
Last active April 12, 2021 14:18
A way to create schedulable jobs that do not block deployments
/***
Adapted from the great Dan Appleman.
For more on this and many other great patterns - buy his book - http://advancedapex.com/
This class can be used to schedule any scheduled job without risk of locking the class.
DO NOT CHANGE THIS CLASS! It is locked by the scheduler. Instead make changes to ScheduledHelper or your own IScheduleDispatched class
To use:
1) Create a new class to handle your job. This class should implement SchedulableWrapper.IScheduleDispatched
2) Create a new instance of SchedulableWrapper with the type of your new class.
3) Schedule the SchedulableWrapper instead of directly scheduling your new class.
See ScheduledRenewalsHandler for a working example.
@gbutt
gbutt / sfdc-new-release-notes.user.js
Last active February 2, 2021 14:05
Creates link to new SFDC Release Notes from old Release Notes
// ==UserScript==
// @name Redirect to new SFDC release notes
// @namespace https://gist.github.com/gbutt/e62c691887887b8287b382455c0194c9
// @version 0.1
// @description Injects a link to new SFDC Release Notes into the old Release Notes page
// @author Greg Butt
// @match https://releasenotes.docs.salesforce.com/*
// @grant none
// ==/UserScript==
@gbutt
gbutt / create-destructive-changes.sh
Created January 26, 2021 20:34
Destructive changes using git diff
#!/bin/bash
write_xml () {
local type_name="$1"
shift
local type_arry=("$@")
XML="${XML}\n\t<types>\n\t\t<name>${type_name}</name>"
for FILENAME in "${type_arry[@]}"; do
XML="${XML}\n\t\t<members>${FILENAME}</members>"
done
@gbutt
gbutt / Toggles.cls
Created January 18, 2021 15:58
Simple feature toggles in Salesforce
public without sharing class Toggles {
private static final Map<String, Boolean> TOGGLE_CACHE;
static {
TOGGLE_CACHE = new Map<String, Boolean>();
loadToggles();
}
// temporary toggle - remove after enabled
public static Boolean DISABLE_CERT_MEMBERSHIP_EXTENSIONS {
@gbutt
gbutt / LaunchScreenFlow.cmp
Last active December 18, 2020 16:54
LaunchScreenFlow
<aura:component implements="forceCommunity:availableForAllPageTypes">
<aura:attribute name="label" type="String" required="true" />
<aura:attribute name="flowApiName" type="String" required="true" />
<aura:attribute name="recordId" type="String" />
<aura:attribute name="buttonStretched" type="Boolean" default="true" />
<aura:attribute name="buttonVariant" type="String" required="true" />
<aura:attribute name="buttonPadding" type="String" required="true" />
<aura:attribute name="buttonClasses" type="String" />
<aura:attribute name="overLayModal" type="Object" />
@gbutt
gbutt / DependencyResolver.cls
Created November 3, 2020 20:00
DependencyResolver.cls
public class DependencyResolver {
@TestVisible
private static Map<Type, Object> cachedDependencies {get; set;}
static {
cachedDependencies = new Map<Type, Object>();
}
// core methods abstract the core logic
public static Object getInstance(Type classType) {
@gbutt
gbutt / StubProviderImpl.cls
Created November 3, 2020 19:58
StubProviderImpl.cls
@IsTest
public class StubProviderImpl implements System.StubProvider {
public Type mockType {get; private set;}
private Map<String, Object> mockedCalls {get; set;}
private Map<String, Exception> mockedExceptions {get; set;}
private Map<String, Object[]> callLog {get; set;}
public StubProviderImpl(Type mockType) {
@IsTest(IsParallel = true)
public class TimezoneTest {
@TestSetup
static void makeData() {
update new User(Id = UserInfo.getUserId(), TimeZoneSidKey = 'America/Denver');
}
@IsTest
static void it_should_demonstrate_datetime_handling_with_timezones() {