This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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: '; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
OlderNewer