Skip to content

Instantly share code, notes, and snippets.

View capeterson's full-sized avatar

Chris Peterson capeterson

View GitHub Profile
@capeterson
capeterson / Explicit.xml
Created October 17, 2011 21:17
Visualforce Inline Help
<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>
@capeterson
capeterson / gist:1241267
Created September 25, 2011 22:37
Tag Upload Page
<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 / gist:1241262
Created September 25, 2011 22:34
Tag Upload Controller
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(){
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){
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
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
public class OhGodBees extends Exception{}
//fails: OhGodBees: Classes extending Exception must have a name ending in 'Exception'
#!/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:
Account a1 = new Account(name = 'woop');
Account a2 = new Account(name = 'woop');
System.debug( a1 == a2 ); //true
System.debug( a1 === a2 ); //false
final String MY_NAMESPACE_PREFIX = 'ns__';
String cleanedJSON = JSON.serialize(subject);
cleanedJSON = cleanedJSON.replaceAll('"'+MY_NAMESPACE_PREFIX+'([a-zA-Z0-9_-]+":)', '"$1');