Skip to content

Instantly share code, notes, and snippets.

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()) {
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;');
@pcon
pcon / backtick_test_status.sh
Last active August 29, 2015 14:07
Screen configuration
#!/bin/bash
/usr/bin/node /home/$USER/bin/test_status.js
@pcon
pcon / TestData1.cls
Last active August 29, 2015 14:14
Fun with maps and sets
class TestData {
public String data;
public TestData() {}
public TestData(String data) {
this.data = data;
}
}
@pcon
pcon / objDesc.html
Last active August 29, 2015 14:14
Object Description
<apex:page docType="html-5.0" showHeader="false" applyBodyTag="false" applyHtmlTag="false" standardStylesheets="false">
<html ng-app="objDescApp">
<head>
<title>Object Description</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" />
<style>body{padding-top:50px}.sub-header{padding-bottom:10px;border-bottom:1px solid #eee}.navbar-fixed-top{border:0}.sidebar{display:none}@media (min-width:768px){.sidebar{position:fixed;top:51px;bottom:0;left:0;z-index:1000;display:block;padding:20px;overflow-x:hidden;overflow-y:auto;background-color:#f5f5f5;border-right:1px solid #eee}}.nav-sidebar{margin-right:-21px;margin-bottom:20px;margin-left:-20px}.nav-sidebar>li>a{padding-right:20px;padding-left:20px}.nav-sidebar>.active>a,.nav-sidebar>.active>a:focus,.nav-sidebar>.active>a:hover{color:#fff;background-color:#428bca}.main{padding:
@pcon
pcon / barracks.txt
Last active August 29, 2015 14:15
Bitmath
┌─┬───────────── Not used.
│ │ ┌─────────── Bottom Ranged
│ │ │ ┌───────── Bottom Melee
│ │ │ │ ┌─────── Middle Ranged
│ │ │ │ │ ┌───── Middle Melee
│ │ │ │ │ │ ┌─── Top Ranged
│ │ │ │ │ │ │ ┌─ Top Melee
│ │ │ │ │ │ │ │
0 0 0 0 0 0 0 0