Skip to content

Instantly share code, notes, and snippets.

Avatar

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
View serve.py
#!/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):
try:
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);
System.assertEquals(
String.valueOf(someId).subString(0,15),
String.valueOf(fixedCase).substring(0,15)
); //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(Trigger.new,'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
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){
this.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:form>
<apex:pageBlock>
<apex:pageBlockButtons>
<apex:commandButton action="{!save}" value="Save" />
</apex:pageBlockButtons>
Select a document: <apex:inputField value="{!documentSelector.itemId}" />
</apex:pageBlock>
</apex:form>
</apex:page>
@capeterson
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%" />
</apex:pageBlockSectionItem>
</apex:repeat>
</apex:pageBlockSection>