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 / BehaviorUnexpectedForStringValueOfWithDateAndDateTime.cls
Last active December 24, 2015 13:29
Unexpected result when using String.valueOf() to get the value of a Date and DateTime, when using an Object reference.
// Asserts fail for the following
/////////////////////////////////
DateTime dt = DateTime.now(); // VARIABLE_ASSIGNMENT dt = 2013-10-03T05:35:37.373Z
System.assertEquals(String.valueOf(dt), String.valueOf((Object) dt));
// Assertion Failed: Expected: 2013-10-02 22:35:37, Actual: 2013-10-03 05:35:37
Date d = Date.today(); // VARIABLE_ASSIGNMENT d = 2013-10-02T00:00:00.000Z
System.assertEquals(String.valueOf(d), String.valueOf((Object) d));
// Assertion Failed: Expected: 2013-10-02, Actual: 2013-10-02 00:00:00
@alan-morey
alan-morey / ForceService.groovy
Created November 24, 2012 01:29
Simple wrapper for querying Salesforce using PartnerConnection in Groovy. Dependencies are pulled in from maven repository via Grape.
@Grab(group='com.force.sdk', module='force-connector', version='22.0.9-BETA')
import com.force.sdk.connector.ForceConnectorConfig
import com.force.sdk.connector.ForceServiceConnector
import com.sforce.soap.partner.PartnerConnection
import com.sforce.soap.metadata.FileProperties
import com.sforce.soap.metadata.ListMetadataQuery
import java.net.URLEncoder
@alan-morey
alan-morey / DescribeMetadataResultFileParser.php
Created November 1, 2012 16:27
PHP classes to parse result files from the Force.com Mirgration Tool "describeMetadata" and "listMetadata" ant tasks.
<?php
class DescribeMetadataResultFileParser {
const BOUNDARY = '************************************************************';
const XML_NAME_MARKER = 'XMLName: ';
const DIR_NAME_MARKER = 'DirName: ';
const SUFFIX_MARKER = 'Suffix: ';
const HAS_META_FILE_MARKER = 'HasMetaFile: ';
const IN_FOLDER_MARKER = 'InFolder: ';
const CHILD_OBJECTS_MARKER = 'ChildObjects: ';
@alan-morey
alan-morey / ScheduleUtil.cls
Created July 24, 2012 21:46
Apex ScheduleUtil
global class ScheduleUtil {
global static String cronExpression(DateTime dt) {
return dt.format('s m H d M ? yyyy');
}
static testMethod void testCronExpression() {
DateTime dt = DateTime.now();
String expected = dt.second() + ' ' + dt.minute() + ' ' + dt.hour() + ' ' + dt.day() + ' ' + dt.month() + ' ? ' + dt.year();