Skip to content

Instantly share code, notes, and snippets.

Public Class ContactTriggerLogic Extends TriggerHandler {
Map<Id,Account> newMap;
Public ContactTriggerLogic() {
this.newMap = (Map<Id, Account>) Trigger.newMap;
}
Public Contact addSnark(Contact c){
if(!c.lastName.contains(' is awesome!')){
c.lastName = c.lastName + ' is awesome!';
Public Class AccountTriggerLogic Extends TriggerHandler{
//...
}
Trigger DescriptiveTriggerNameHere on ObjectNameHere (execution,context,list){
new YourTriggerLogicClassNameHere().run();
}
IF(
ISBLANK(Line_Item__c),
CASE(
TEXT(Platform_Line_Item__r.Fee_Structure__c),
"Media Spend",
IF(
End_date__c > TODAY(),
Monthly_Projected_Spend__c,
Monthly_Actual_Spend__c
),
//In your test…
@isTest
static void test_method_one() {
//If you're not using SmartFactory, you're doing it way too hard. (and wrong)
Account account = (Account)SmartFactory.createSObject('Account');
insert account;
Test.startTest();
MyFarawayClass.RunMockCalloutForTest(account.id);
Test.StopTest();
}
//In a class far far away...
@future
global static void RunMockCalloutForTest(String accountId){
TestRestClient trc = new TestRestClient();
id aId;
try {
aId = (Id) accountId;
} catch (Exception e) {
throw new exception('Failed to cast given accountId into an actual id, Send me a valid id or else.');
}
List<Contact> PunishIt = new List<Contact>();
for(Integer i = 0; i < 1000; i++) {
PunishIt.add(Conctact c = new contact(fill in missing = stuff here));
}
Insert PunishIt;
Delete PunishIt;
@noeticpenguin
noeticpenguin / GuidUtil.java
Created September 16, 2013 19:51
GuidUtil
global with sharing class GuidUtil {
private static String kHexChars = '0123456789abcdef';
global static String NewGuid() {
String returnValue = '';
Integer nextByte = 0;
for (Integer i=0; i<16; i++) {
if (i==4 || i==6 || i==8 || i==10)
returnValue += '-';
nextByte = (Math.round(Math.random() * 255)-128) & 255;
@noeticpenguin
noeticpenguin / using bulk create for great good.md
Last active December 21, 2015 10:39
If bo is awesome and he knows it send at tweet!

Using the helper methods

ngForce provides some helper methods that are intended to make the developers life simpler. Most of these are self explanitory but a couple of them are a bit more esoteric.

Perhaps the most confusing is the bulkCreate method. You can invoke the bulk create method thusly:

var pBulkCreateCall = vfr.bulkCreate('objectName__c', dataRows);
pBulkCreateCall.then(function(results){
  //do something awesome with results
function getLocaleDateString(){
var formats ={"ar-SA":"dd/mm/yy","bg-BG":"dd.m.yyyy","ca-ES":"dd/mm/yyyy","zh-TW":"yyyy/m/d","cs-CZ":"d.m.yyyy",
"da-DK":"dd-mm-yyyy","de-DE":"dd.mm.yyyy","el-GR":"d/m/yyyy","en-US":"m/d/yyyy","fi-FI":"d.m.yyyy","fr-FR":"dd/mm/yyyy",
"he-IL":"dd/mm/yyyy","hu-HU":"yyyy. mm. dd.","is-IS":"d.m.yyyy","it-IT":"dd/mm/yyyy","ja-JP":"yyyy/mm/dd",
"ko-KR":"yyyy-mm-dd","nl-NL":"d-m-yyyy","nb-NO":"dd.mm.yyyy","pl-PL":"yyyy-mm-dd","pt-BR":"d/m/yyyy",
"ro-RO":"dd.mm.yyyy","ru-RU":"dd.mm.yyyy","hr-HR":"d.m.yyyy","sk-SK":"d. m. yyyy","sq-AL":"yyyy-mm-dd",
"sv-SE":"yyyy-mm-dd","th-TH":"d/m/yyyy","tr-TR":"dd.mm.yyyy","ur-PK":"dd/mm/yyyy","id-ID":"dd/mm/yyyy",
"uk-UA":"dd.mm.yyyy","be-BY":"dd.mm.yyyy","sl-SI":"d.m.yyyy","et-EE":"d.mm.yyyy","lv-LV":"yyyy.mm.dd.",
"lt-LT":"yyyy.mm.dd","fa-IR":"mm/dd/yyyy","vi-VN":"dd/mm/yyyy","hy-Am":"dd.mm.yyyy","az-Latn-AZ":"dd.mm.yyyy",
"eu-ES":"yyyy/mm/dd","mk-mK":"dd.mm.yyyy","af-ZA":"yyyy/mm/dd","ka-GE":"dd.mm.yyyy","fo-FO":"dd-mm-yyyy",