Skip to content

Instantly share code, notes, and snippets.

/**
* 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 / 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
@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);
}
}
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 / 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()) {
@pcon
pcon / CaseTrigger.java
Last active January 24, 2017 16:38
Object Snapshotting
trigger CaseTrigger on Case (after insert) {
ObjectSnapshotUtils.createSnapshots(Trigger.new);
}
Map<DateTime, User> userMap = new Map<DateTime, User>();
for (User u: [select LastLoginDate from User where Id in:userIds]) {
userMap.put(u.LastLoginDate, u);
}
@pcon
pcon / AutoConverter.java
Last active August 29, 2015 14:04
Lead Conversion
Trigger AutoConverter on Lead (after insert) {
LeadStatus convertStatus = [
select MasterLabel
from LeadStatus
where IsConverted = true
limit 1
];
List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
for (Lead lead: Trigger.new) {
/**
* Gets an admin user
*
* @return An admin user
*/
public static User getAdminUser() {
Profile adminProfile = [
select id
from profile
where name = 'System Administrator'
@pcon
pcon / gist:c34dcb7d3f219e3fde02
Created August 19, 2014 19:52
EncodingUtils weirdness
System.debug(System.LoggingLevel.ERROR, '| vs ' + EncodingUtil.urlDecode('%7C;', 'UTF-8'));
if ('|' == EncodingUtil.urlDecode('%7C', 'UTF-8')) {
System.debug(System.LoggingLevel.ERROR, 'Expected: %7C');
} else {
System.debug(System.LoggingLevel.ERROR, 'Unxpected: %7C');
}
System.debug(System.LoggingLevel.ERROR, '| vs ' + EncodingUtil.urlDecode('&#124;', 'UTF-8'));
if ('|' == EncodingUtil.urlDecode('&#124;', 'UTF-8')) {
System.debug(System.LoggingLevel.ERROR, 'Expected: &#124;');