Skip to content

Instantly share code, notes, and snippets.

View jbro-io's full-sized avatar

Jonathan Broquist jbro-io

  • Scottsdale, AZ
View GitHub Profile
trigger AccountTrigger on Account(
before insert,
before update,
before delete,
after insert,
after update,
after delete,
after undelete
) {
AccountTriggerHandler objectHandler = new AccountTriggerHandler(Trigger.operationType);
@isTest
private class TriggerHandlerTest {
// I normally put private classes at the bottom, but to prevent you from having to scroll ...
private class TestTriggerHandler extends TriggerHandler {
public TriggerOperation Method { get; private set; }
@testVisible
protected override void beforeInsert(List<SObject> newRecords) {
this.Method = TriggerOperation.BEFORE_INSERT;
}
public virtual class TriggerHandler {
@testVisible
private static TriggerOperation triggerContext;
protected TriggerHandler() {
if (!Trigger.isExecuting && !Test.isRunningTest()) {
throw new TriggerHandlerException('TriggerHandler used outside of triggers / testing');
}
}
@jbro-io
jbro-io / multiple-bitbucket-ssh-accounts.md
Last active March 18, 2021 03:24
multiple-bitbucket-ssh-accounts

1. Edit ~/.ssh/config

Host bitbucket.org-yourusername
    HostName bitbucket.org
    User yourusername
    IdentityFile ~/.ssh/yoursshkey
    IdentitiesOnly yes
@jbro-io
jbro-io / Apex: Standard Deviation Example
Last active August 28, 2019 14:21
A method for calculating standard deviations with Apex.
public class AdvancedMath
{
public static Double standardDeviation(Double[] numbers)
{
//determine the sum of the range of numbers
Double sum = 0;
for(Double d : numbers)
{
sum += d;
}
@jbro-io
jbro-io / Visualforce: KnockoutJS Statement Component
Last active March 1, 2018 04:34
This is a Visualforce component used to render Knockout.js HTML comment tags.
<apex:component layout="none">
<apex:attribute name="statement"
description="The Knockout containerless statement to insert."
type="String"
required="false"
/>
<apex:attribute name="close"
description="Flag that determines whether this is an opening or closing statement for Knockout."
type="Boolean"
@jbro-io
jbro-io / AngularJS: angular-eventutil.js
Last active September 12, 2017 07:37
Global event dispatcher/listener utility for AngularJS
angular.module('EventUtil', [])
.factory('broadcast', ['$rootScope', function($rootScope){
return function(eventName, payload){
$rootScope.$broadcast(eventName, payload);
};
}])
.factory('listen', ['$rootScope', function($rootScope){
return function(eventName, listener){
$rootScope.$on(eventName, listener);
};
@jbro-io
jbro-io / FindHardCodedURLs.apex
Created October 16, 2016 04:59 — forked from danieljpeter/FindHardCodedURLs.apex
Execute anonymous script to check Email Templates for Hard Coded URLs before turning on My Domain
/*
* Hard coding your Salesforce URL in places like Email Tempaltes and Apex Classes is a worst practice, but some people do it.
* These URLs will break when you turn on my domain, since your URL changes.
* More on this here: https://help.salesforce.com/apex/HTViewSolution?urlname=Updating-Hard-Coded-References-FAQ
* Here are some quick and dirty checks for your Salesforce URL being hard coded in:
* EmailTemplates, WebLinks, ApexClasses, Visualforce Pages, and Triggers.
* Ideally you would retrieve all metadata and search it, but this will find some of the low hanging problems easily.
*
* Usage:
* - Copy / Paste this into Salesforce Execute Anonymous window.
@jbro-io
jbro-io / Visualforce: DateFormat
Last active December 29, 2015 07:39
Displays how to format a date field on a Visualforce page.
<apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
<apex:param value="{!task.ActivityDate}" />
</apex:outputText>