Skip to content

Instantly share code, notes, and snippets.


Chris Peterson capeterson

View GitHub Profile
View gist:9731104
final String MY_NAMESPACE_PREFIX = 'ns__';
String cleanedJSON = JSON.serialize(subject);
cleanedJSON = cleanedJSON.replaceAll('"'+MY_NAMESPACE_PREFIX+'([a-zA-Z0-9_-]+":)', '"$1');
View gist:11231360
Account a1 = new Account(name = 'woop');
Account a2 = new Account(name = 'woop');
System.debug( a1 == a2 ); //true
System.debug( a1 === a2 ); //false
#!/usr/bin/env python
import os, sys, re
from os import curdir, sep
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
View name.cls
public class OhGodBees extends Exception{}
//fails: OhGodBees: Classes extending Exception must have a name ending in 'Exception'
View gist:721491e539606ba728d3
Account a = [SELECT id, name, description FROM Account LIMIT 1];
a.description = 'This code with person accounts on is like playing russion roulete';
update a; //DMLException if you got a person account, works otherwise
View Id.cls
Id someId = [SELECT id FROM Contact LIMIT 1].Id;
String ruinedCase = ((String)someId).toLowerCase();
Id fixedCase = Id.valueOf(ruinedCase);
); //fails, for me: System.AssertException: Assertion Failed: Expected: 003i000002O2aZG, Actual: 003i000002o2azg
View gist:1207674
trigger CountIncidents on itil_b__Incident__c (after insert, after update){
List<Id> AccountIDs = itil_b.Util.getIDFields(,'itil_b__account__c');
List<AggregateResult> totalIncidents = [SELECT itil_b__Account__c, COUNT(Id)
FROM itil_b__Incident__c WHERE itil_b__Account__c IN :AccountIDs AND itil_b__Account__c != null
GROUP BY ROLLUP(itil_b__Account__c)];
Map<id,Account> accounts = new Map<id,Account>([SELECT total_incidents__c, id FROM Account WHERE Id IN :accountIDs]);
for(AggregateResult ar: totalIncidents){
capeterson / gist:1241262
Created Sep 25, 2011
Tag Upload Controller
View gist:1241262
public with sharing class TagDemoController {
Public ApexPages.StandardController sc {get; set;}
public DocumentTag documentSelector {get; set;}
public TagDemoController(ApexPages.StandardController sc){ = sc;
documentSelector = new DocumentTag(); //Initialize our tag to avoid a null pointer
public PageReference save(){
View gist:1241267
<apex:page standardController="SomeObject__c" extensions="TagDemoController">
<apex:commandButton action="{!save}" value="Save" />
Select a document: <apex:inputField value="{!documentSelector.itemId}" />
capeterson / Explicit.xml
Created Oct 17, 2011
Visualforce Inline Help
View Explicit.xml
<apex:pageBlockSection columns="1">
<apex:repeat value="{!$ObjectType.Incident__c.FieldSets.PortalNewLower}" var="field">
<apex:pageBlockSectionItem helpText="{!$ObjectType.Incident__c.Fields[field].InlinehelpText}">
<apex:outputLabel value="{!field.label}" />
<apex:inputField value="{!newIncident[field]}" required="{!field.required || field.DBRequired}" style="width:65%" />