Skip to content

Instantly share code, notes, and snippets.

View ralphcallaway's full-sized avatar

Ralph Callaway ralphcallaway

View GitHub Profile
@ralphcallaway
ralphcallaway / jQuery.component
Created November 9, 2012 22:19
Salesforce component for adding jQuery to a visualforce page
<apex:component >
<apex:attribute name="version"
type="String"
required="false"
description="Version of jquery. Defaults to 1.8.2. See https://developers.google.com/speed/libraries/devguide#jquery for a full list of available versions"
default="1.8.2"/>
<apex:attribute name="minified"
type="Boolean"
required="false"
@ralphcallaway
ralphcallaway / snippet.cls
Created November 9, 2012 22:30
Example of good exception handling for vf pages
public void functionWithDML() {
try {
insert listOfStuff;
} catch(DMLException e1) {
// do nothing here, page messages are automatically generated
} catch(Exception e2) {
// uh-oh, something else happened bad, better show it to the user
ApexPages.addMessage(
new ApexPages.Message(
ApexPages.Severity.ERROR
@ralphcallaway
ralphcallaway / AccountView.cls.java
Created November 21, 2012 21:28
Massive Internal View State (file extensions changed to assist with language auto-detection) See http://salesforce.stackexchange.com/questions/4537/how-to-reduce-a-large-internal-view-state-what-is-in-the-internal-view-state for related discussion
/* NB: Class has been edited for brevity and may not compile initially */
public with sharing class AccountView {
// Input Properties
public String filter1 { get; set; }
public String grouping1 { get; set; }
public String grouping2 { get; set; }
// Select Lists
@ralphcallaway
ralphcallaway / AnotherWay.html
Created November 26, 2012 16:02
Alternative Implementation of Client Preferces
<apex:form >
<apex:pageBlock id="cp_module" rendered="{!detailKey = 'cp'}" title="Client Preferences" mode="edit">
<apex:pageblockButtons location="top">
<apex:commandButton value="Edit" rendered="{!NOT(clientPreferencesModification)}"
rerender="cp_module" status="LoadingStatusSpinner">
<apex:param assignTo="{!clientPreferencesModification}" value="true"/>
</apex:commandButton>
<apex:commandButton value="Save" rendered="{!clientPreferencesModification}"
action="{!saveClientPreferences}" status="LoadingStatusSpinner"
rerender="cp_module, im_counts"/>
/*
Developer: Ralph Callaway <[email protected]>
Description: Helper methods for dynamic DML
*/
public class DynamicDMLHelper {
public static Object recursiveGet(sObject record, String field) {
if(field.contains('.')) {
Integer firstPeriod = field.indexOf('.');
String nextObjectName = field.subString(0, firstPeriod);
@ralphcallaway
ralphcallaway / destructiveChanges.xml
Created February 25, 2013 23:39
Clean a new Salesforce dev org
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<version>26.0</version>
</Package>
@ralphcallaway
ralphcallaway / AccountHierarchy.cls
Created October 25, 2013 17:13
Sample code for working with account hierarchies
/*
Developer: Ralph Callaway <[email protected]>
Description:
Representation of an account hierarchy.
*/
public class AccountHierarchy {
/* Variables */
private Boolean accountsLoaded = false;
# Eclipse Project Files
com.salesforce.ide.core.prefs
salesforce.schema
Referenced Packages
.project
# Maven’s Mate Generated Files
apex-scripts
config
debug
# Eclipse Project Files
com.salesforce.ide.core.prefs
salesforce.schema
Referenced Packages
.project
# Maven’s Mate Generated Files
apex-scripts
config
debug
@ralphcallaway
ralphcallaway / andyIsAwesome.r
Last active August 29, 2015 14:22
Submission by reference - June Salesforce Hack of the Month Submission
# /usr/bin/env copy
import http://andyinthecloud.com/2015/05/25/automating-org-setup-via-process-builder-and-metadata-api/
# no rules rulez!