Skip to content

Instantly share code, notes, and snippets.

@pcon
pcon / ExampleClass.cls
Last active August 29, 2015 14:16
Testing Strategy Code
public static String uppercase(String name) {
if (name == null) {
return 'NULL';
}
if (name.trim() == '') {
return 'BLANK';
}
return name.toUpperCase();
@pcon
pcon / APIUtils.java
Last active September 28, 2015 18:48
Web-services examples in Salesforce
/**
* This class is a utility class for WebServices and other API classes
*/
global with sharing class APIUtils {
global final static Integer STATUS_OK = 200;
global final static Integer STATUS_CREATED = 201;
global final static Integer STATUS_ACCEPTED = 202;
global final static Integer STATUS_BAD = 400;
global final static Integer STATUS_FORBIDDEN = 403;
global final static Integer STATUS_NOTFOUND = 404;
@pcon
pcon / MyObjectTrigger.java
Created December 15, 2011 15:42
Classifying triggers in Salesforce
public class MyObjectTrigger {
private final Map<Id, MyObject__c> oldMap;
private final Map<Id, MyObject__c> newMap;
private final List<MyObject__c> newObjs;
private final Boolean isInsert;
private final Boolean isUpdate;
private final Boolean isDelete;
private final Boolean isBulk;
/**
@pcon
pcon / .vimrc
Created February 9, 2012 16:39
salesforce vim config options
" General stuff
set nocompatible
filetype on
set background=light
syntax on
" don't make it look like there are line breaks where there aren't:
set nowrap
@pcon
pcon / CaseTrigger.java
Last active October 2, 2015 19:08
Salesforce Static variable with dynamic assignment
MyObject__c obj = MyObjectUtils.myObjectMap.get('Foo');
@pcon
pcon / template.java
Created May 22, 2012 18:57
Pcon trigger template.java
public class OrderTrigger {
private final Map<Id, Order__c> oldMap;
private final Map<Id, Order__c> newMap;
private final List<Order__c> newObjs;
private final Boolean isInsert;
private final Boolean isUpdate;
private final Boolean isDelete;
private final Boolean isBulk;
/**
@pcon
pcon / scheduledMonthly.java
Last active October 5, 2015 09:58
Scheduled Apex
/**
* To schedule the monthly reconciliation:
* NOTE: It should run at midnight on the first of every month on it's own, but if you make
* changes and need to requeue run the command below from the developer's console
*
* scheduledMonthly.scheduleIt();
*/
global class scheduledMonthly implements Schedulable {
public static String CRON_EXP = '0 0 0 1 * ? *';
@pcon
pcon / ServiceRequestTrigger.java
Created May 30, 2012 18:01
Checking previous status != 'In Review' and then switched to 'In Review' - field expression now allowed for generic SObject line 33
public class ServiceRequestTrigger {
private final Map<Id, Service_Request__c> oldMap;
private final Map<Id, Service_Request__c> newMap;
private final List<Service_Request__c> newObjs;
private final Boolean isInsert;
private final Boolean isUpdate;
private final Boolean isDelete;
private final Boolean isBulk;
/**
@pcon
pcon / ServiceRequestTrigger.java
Created May 31, 2012 18:29
Checking previous status != 'In Review' and then switched to 'In Review' - field expression now allowed for generic SObject line 33
public class ServiceRequestTrigger {
private final Map<Id, Service_Request__c> oldMap;
private final Map<Id, Service_Request__c> newMap;
private final List<Service_Request__c> newObjs;
private final Boolean isInsert;
private final Boolean isUpdate;
private final Boolean isDelete;
private final Boolean isBulk;
/**
@pcon
pcon / swap.sh
Created July 3, 2012 14:08
swap function
function swap() {
TMP_NAME="TMP_$RANDOM"
mv "$1" "/tmp/$TMP_NAME" && mv "$2" "$1" && mv "/tmp/$TMP_NAME" "$2"
}