Skip to content

Instantly share code, notes, and snippets.

//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.');
}
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
),
Trigger DescriptiveTriggerNameHere on ObjectNameHere (execution,context,list){
new YourTriggerLogicClassNameHere().run();
}
Public Class AccountTriggerLogic Extends TriggerHandler{
//...
}
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 ContactTriggerLogic Extends TriggerHandler {
Public ContactTriggerLogic() {
this.setMaxLoopCount(1);
}
}
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
/*
Copyright (c) 2011, salesforce.com, inc. All rights reserved.
Redistribution and use of this software in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials provided
with the distribution.
class InitialViewController < UIViewController
def initWithNibName(nibNameOrNil, bundle:nibBundleOrNil)
super.initWithNibName(nibNameOrNil, bundle:nibBundleOrNil)
p "Inside InitialViewController"
if self
# Custom init code goes here
end
self
end