Skip to content

Instantly share code, notes, and snippets.

public override void afterUpdate() {
this.bypass('AccountTriggerHandler'); //yeah, if you could just ignore that accountTrigger, *that'd be great*
acc.Name = 'No Trigger'; // wait! where'd acc come from? … just keeping you on your toes.
update acc; // won't invoke the AccountTriggerHandler
this.clearBypass('AccountTriggerHandler'); // actually, yeah. need you run that accountTrigger.
acc.Name = 'With Trigger';
update acc; // will invoke the AccountTriggerHandler
Public Class ContactTriggerLogic Extends TriggerHandler {
Public ContactTriggerLogic() {
this.setMaxLoopCount(1);
}
}
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 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.');
}
//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();
}
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;