Skip to content

Instantly share code, notes, and snippets.

View alan-morey's full-sized avatar

Alan Morey alan-morey

View GitHub Profile
@alan-morey
alan-morey / XmlStarlet.txt
Last active October 30, 2017 17:08
XmlStarlet
Salesforce package.xml
xmlstarlet sel -t -m _:Package/_:types -s A:T:U _:name -n -v _:name -n -m _:members -s A:T:U . -v "concat(' - ', .)" -n package.xml
xmlstarlet sel -t -m _:Package/_:types -s A:T:U _:name -m _:members -s A:T:U . -v "concat(../_:name, '::', .)" -n package.xml
@alan-morey
alan-morey / keybase.md
Created October 20, 2017 21:33
keybase.md

Keybase proof

I hereby claim:

  • I am alan-morey on github.
  • I am alanmorey (https://keybase.io/alanmorey) on keybase.
  • I have a public key ASC_PfYGuMi76Hro7GXR8FQJowknG2Za0s0RWmEZaELM3wo

To claim this, I am signing this object:

class SetupAuditTrails {
public Map<String, Set<String>> getModifiedClassesSince(Id sinceTrailId) {
return getModifiedClassesSince(sinceDate(sinceTrailId));
}
public Map<String, Set<String>> getModifiedClassesSince(DateTime sinceDate) {
Map<String, Set<String>> changes = new Map<String, Set<String>>();
for (SetupAuditTrail t : [
SELECT display
@alan-morey
alan-morey / AnonApp.cls
Last active January 8, 2016 23:58
Wrapper for running anonymous code blocks in Salesforce, print() and println() allow you to write messages to a single output stream and have the out rendered to debug log and also in an AlertException. The AlertException is the always thrown at end of execution which ensures that nothing is ever committed to the Database.
public abstract class AnonApp implements MainMethod {
final String[] OUT = new String[0];
public static void run(Type clazz) {
AnonApp app = (AnonApp) clazz.newInstance();
app.run();
}
public void run() {
try {
@alan-morey
alan-morey / Uuid.cls
Last active August 29, 2015 14:18
UUID Apex
public class Uuid {
static final String GROUP_SEP = '-';
Uuid() {}
public static String randomUuid() {
String hex = EncodingUtil.convertToHex(Crypto.generateAesKey(128));
return String.join(new String[] {
hex.substring(0,8),
@alan-morey
alan-morey / SystemHashCodeBugTest.cls
Created April 6, 2015 19:33
Salesforce Spring '15 - System.hashCode() producing unexpected result when using same value with different reference types.
// Unexpected results for System.hashCode() when using same values for Salesforce IDs with different reference types.
//
// https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_system.htm?CSHID=apex_methods_system_system.htm#apex_system_system_hashcode
//
// API v33
@isTest
class SystemHashCodeBugTest {
static final String STR_VAL = 'foobar';
static final Id USER_ID_VAL = UserInfo.getUserId();
static final Id LITERAL_ID_VAL = '001000000000001';
@alan-morey
alan-morey / LongAndIntegerMinValueLiteralBug.cls
Created October 1, 2014 22:44
Salesforce Apex bug with Long and Integer when trying to represent the minimum value as a literal
// Apex seems to have a bug when trying to represent the minimum value for both
// Long and Integer primitive types as a literal value.
//
//Long MIN_LONG = -9223372036854775808L; // Compile Error: Invalid Long: 9223372036854775808L
//Integer MIN_INT = -2147483648; // Compile Error: Invalid Integer: 2147483648
// Workaround: Overflow the MAX values
Long LONG_MAX_VALUE = 9223372036854775807L;
Long LONG_MIN_VALUE = LONG_MAX_VALUE + 1; // Overflow => -9223372036854775808L
@alan-morey
alan-morey / Anonymous.cls
Last active August 29, 2015 14:02
Possible regression in Apex equals() implementation with Salesforce Summer '14
public class PairNumbers {
Integer x,y;
public PairNumbers(Integer a, Integer b) {
x=a;
y=b;
}
public Boolean equals(Object obj) {
if (obj != null && obj instanceof PairNumbers) {
/**
* Salesforce does not allow the ability to write to certain SObject fields
* such as LastModifiedDate, CreatedDate etc. Even if those objects are
* not going to be inserted into the DB. This makes testing around these
* fields difficult as we always need to hit the database to load these values
* and it's not possible to inject the values you require.
*
* This method gets around that limitation by using JSON. We first create
* a representation of the data as a map of fields/values pairs. Then we
* transform the map into a JSON representation. This respresentation includes
@alan-morey
alan-morey / TestSpy.cls
Last active August 29, 2015 13:57
Apex Test Spy
@isTest
public class TestSpy {
public static final String UNKNOWN = '<unknown>';
public static final String VOID_RETURN_TYPE = '<void>';
String methodName;
List<Object[]> callArgs;
Exception throwResult;
Boolean isVoidReturn = true;