Skip to content

Instantly share code, notes, and snippets.

@pcon
pcon / CaseTrigger.java
Last active January 24, 2017 16:38
Object Snapshotting
trigger CaseTrigger on Case (after insert) {
ObjectSnapshotUtils.createSnapshots(Trigger.new);
}
@pcon
pcon / CaseTrigger.java
Created March 28, 2014 13:01
How to make a trigger not run based on a static variable
//This would actually be your CaseTrigger.trigger but the hilighting wouldn't work then
List<ChatterPost> postsToInsert = new List<ChatterPost>();
for (Case c: trigger.new) {
if (c.Status == 'collab') {
postsToInsert.add(new ChatterPost(...));
}
if (!postsToInsert.isEmpty()) {
Map<String, Profile> profileMap {
get {
if (profileMap == null) {
profileMap = new Map<String, Profile>();
for (Profile p: [
select Name
from Profile
]) {
profileMap.put(p.Name, p);
@pcon
pcon / gist:8363353
Created January 10, 2014 21:49
Pattern Matcher SFDC
public static String extractRefId(String orgId, String testString) {
pattern myPattern = pattern.compile('(?m).*\\[ ref:(.*)\\.(.*):ref \\].*');
matcher myMatcher = myPattern.matcher(testString);
if (myMatcher.matches()) {
if (myMatcher.group(1) == orgId) {
return myMatcher.group(2);
}
}
@pcon
pcon / agent.nut
Last active January 2, 2016 00:39
Pushover Electric Imp
//Agent code
function send_pushover(title, message, priority) {
local url = "https://api.pushover.net/1/messages.json";
local token="XXX_TOKENGOESHERE_XXX";
local user="XXX_USERGOESHERE_XXX";
local headers = { "Content-Type": "application/x-www-form-urlencoded" };
local data = {
"token": token,
"user": user,
"message": message
/**
* Utility methods for use with the Object Snapshot object
*
* @author Patrick Connelly
*/
public with sharing class ObjectSnapshotUtils {
public static String JSON_DELIMITER = '[delimiter]';
public static Integer JSON_FIELD_SIZE = 32768 - (JSON_DELIMITER.length() * 2);
public static Integer JSON_FIELD_COUNT = 10;
@pcon
pcon / gist:7452472
Last active November 25, 2019 15:53
/**
* Sleep at least a second
*
* Found at: http://boards.developerforce.com/t5/Apex-Code-Development/Best-way-to-delay-until-time-changes-in-a-test/td-p/389619
*
*/
public static void waitAtLeastASecond() {
Integer msPerS = 1000;
Datetime start = Datetime.now();
Datetime current = Datetime.now();
@pcon
pcon / gist:7122968
Last active December 26, 2015 08:29
#
# Define some colors first: Capitals denote bold
#
red='\e[0;31m'
RED='\e[1;31m'
green='\e[0;32m'
GREEN='\e[1;32m'
yellow='\e[0;33m'
YELLOW='\e[1;33m'
blue='\e[0;34m'
/*jslint browser: true, regexp: true */
/*global casper, require, jQuery*/
var BASE_URL, LOGIN_URL, LOGIN_USERNAME, LOGIN_PASSWORD, SCHEDULED_JOBS_URI, casp;
casp = require('casper').create({
clientScripts: [
'jquery.min.js'
],
viewportSize: {
@pcon
pcon / sfdclogin.casper.js
Last active December 19, 2015 12:49
CasperJs logging into Salesforce
/*jslint browser: true, regexp: true */
/*global casper, require */
var LOGIN_URL, LOGIN_USERNAME, LOGIN_PASSWORD, casp;
casp = require('casper').create({
viewportSize: {
width: 1024,
height: 768
},