Skip to content

Instantly share code, notes, and snippets.

@dhoechst
dhoechst / 1 - Singleton
Last active December 23, 2015 12:39
Trying to understand the singleton pattern and why some people consider it bad.
// from http://wiki.developerforce.com/page/Apex_Design_Patterns_-_Singleton
// What makes this a singleton pattern? Is it that it uses a private constructor?
public class AccountFooRecordType {
// private static variable referencing the class
private static AccountFooRecordType instance = null;
public String id {get;private set;} // the id of the record type
// The constructor is private and initializes the id of the record type
private AccountFooRecordType(){
@dhoechst
dhoechst / OpportunityNewDispatcher
Last active August 29, 2015 14:01
Creating a Dispatcher
<apex:page standardController="Opportunity"
extensions="OpportunityNewDispatcherController"
action="{!redirect}">
</apex:page>
@dhoechst
dhoechst / 0-ApexTestingBestPractices.md
Last active April 28, 2022 03:30
Testing Best Practices and Examples

This Gist shows code examples for Apex Testing Best Practices. It relys on having the TestFactory in your org.

@dhoechst
dhoechst / 0-SuperDuperSetting.page
Last active August 29, 2015 14:04
Custom Settings Update
<apex:page controller="SuperDuperSettingController">
<apex:pageMessages />
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel >Name</apex:outputLabel>
<apex:inputText value="{!setting.Name}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
@dhoechst
dhoechst / SchedulableDemo
Created October 22, 2014 04:15
SchedulableDemo
public class SchedulableDemo implements Schedulable{
public Integer counter;
public void execute(SchedulableContext sc) {
if (counter == null) {
counter = 1;
} else {
counter ++;
}
@dhoechst
dhoechst / DataTableAjax
Last active July 23, 2021 01:29
Datatable Example
<apex:page>
<head>
<apex:includescript value="//code.jquery.com/jquery-1.11.1.min.js" / >
<apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" />
<apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" />
<!-- I have a static resource called famfamfam which is the zip file from http://www.famfamfam.com/lab/icons/silk/famfamfam_silk_icons_v013.zip -->
<style>
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Accounts_with_Leads_2</members>
<members>Accounts_with_leads</members>
<name>ReportType</name>
</types>
<version>38.0</version>
</Package>
@dhoechst
dhoechst / customlabels.eml
Created March 20, 2017 02:19
Custom Label Email Template
<messaging:emailTemplate subject="{!SUBSTITUTE($Label.AccountEmailSubject,'{0}', relatedTo.Name)}"
relatedToType="Account" language="{!relatedTo.Language__c}">
<messaging:htmlEmailBody >
{!$Label.EmailBody}
</messaging:htmlEmailBody>
</messaging:emailTemplate>
@dhoechst
dhoechst / 1 - DynamicEmailController.class
Last active March 21, 2017 04:58
Dynamic Email Templates
public class DynamicEmailController {
public DynamicEmailController() {}
public String emailRelatedToId {get; set;}
public String emailTemplateId {get; set;}
public Boolean isHtml {get; set;}
private Messaging.SingleEmailMessage renderedEmail {
get {
@dhoechst
dhoechst / package.xml
Created July 3, 2017 16:49
Package.xml for metadate retrieval
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>Profile</name>
</types>
<types>
<members>MyTab</members>
<name>CustomTab</name>
</types>