Skip to content

Instantly share code, notes, and snippets.

trigger RestrictInvoiceDeletion on Invoice__c (before delete) {
// With each of the invoice statements targeted by the trigger
// and that have line items, add an error to prevent them
// from being deleted.
for (Invoice__c invoice :
[SELECT Id
FROM Invoice__c
WHERE Id IN (SELECT Invoice__c FROM Line_Item__c) AND
Id IN :Trigger.old]){
Trigger.oldMap.get(invoice.Id).addError('Cannot delete invoice statement with lineitems');
@joshbirk
joshbirk / CreateMerch.cls
Created March 10, 2014 20:29
New Execute Anonymous
// Create Warehouse if one does not exist
Warehouse__c w;
List<Warehouse__c> warehouse = [SELECT ID from Warehouse__c];
if(warehouse.size() == 1) {
w = new Warehouse__c(
Name='Warehouse 1',
City__c='San Francisco',
Location__Latitude__s=37.7833,
Location__Longitude__s=122.4167);
@isTest
private class TestCleanUpBatchClass {
static testmethod void test() {
// The query used by the batch job.
String query = 'SELECT Id,CreatedDate FROM Merchandise__c ' +
'WHERE Id NOT IN (SELECT Merchandise__c FROM Line_Item__c)';
// Create some test merchandise items to be deleted
// by the batch job.
Warehouse__c w = new Warehouse__c(
@joshbirk
joshbirk / TestFactory.cls
Created March 10, 2014 19:53
New TestFactory
@isTest
public class TestDataFactory {
public static Invoice__c createOneInvoiceStatement(
Boolean withLineItem) {
// Create Warehouse if one does not exist
Warehouse__c w;
List<Warehouse__c> warehouse = [SELECT ID from Warehouse__c];
if(warehouse.size() == 0) {
@joshbirk
joshbirk / CanJSDemo.page
Created February 26, 2014 22:36
Visualforce Remote Objects example using the CanJS framework
<apex:page showHeader="false" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false">
<HTML>
<HEAD>
<script src="{!URLFOR($Resource.jquery)}"></script>
<script src="{!URLFOR($Resource.CanJS,'can.jquery.js')}"></script>
<script src="{!URLFOR($Resource.bootstrap,'js/bootstrap.js')}"></script>
<link rel="stylesheet" href="{!URLFOR($Resource.bootstrap, 'css/bootstrap.css')}"></link>
<apex:remoteObjects >
<apex:remoteObjectModel name="Contact" jsShorthand="contact" fields="Name,Id,Email"/>
<script>
@joshbirk
joshbirk / BlogLog_Retrieve.cls
Created January 14, 2014 22:09
Class which retrieves from RSS and Twitter JSON
global with sharing class BlogLog_Retrieve implements Schedulable {
public BlogLog_Retrieve() {}
global void execute(SchedulableContext c) {
updateBlogData();
updateTwitterData();
}
global class BlogPost {
@joshbirk
joshbirk / BlogLog_Services.cls
Created January 14, 2014 21:52
Apex Class for Email Services
global class BlogLog_Services implements Messaging.InboundEmailHandler {
public BlogLog_Services() {}
public Document document {
get {
if (document == null)
document = new Document();
return document;
}
<apex:page docType="html-5.0"
showHeader="false" sidebar="false" applyBodyTag="false" standardStylesheets="false">
<apex:stylesheet value="{!URLFOR($Resource.OneCSS,'icons.css')}"/>
<apex:stylesheet value="{!URLFOR($Resource.OneCSS,'styles.css')}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery)}"/>
<apex:includeScript value="{!URLFOR($Resource.TouchSwipe,'jquery.touchSwipe.min.js')}"/>
<head>
<title>S1 Starter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
@joshbirk
joshbirk / VehicleList.page
Last active December 31, 2015 02:19
CanJS + RemoteObjects
<apex:page showHeader="false" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false">
<HTML>
<HEAD>
<script src="{!URLFOR($Resource.jquery)}"></script>
<script src="{!URLFOR($Resource.canjs)}"></script>
<script src="{!URLFOR($Resource.bootstrap,'js/bootstrap.js')}"></script>
<link rel="stylesheet" href="{!URLFOR($Resource.bootstrap, 'css/bootstrap.css')}"></link>
<apex:remoteObjects >
<apex:remoteObjectModel name="blitz4lifeU__Vehicle__c" jsShorthand="Vehicle" fields="Name,Id,blitz4lifeU__Make__c ,blitz4lifeU__Model__c,blitz4lifeU__Wheels__c"/>
<script>
@joshbirk
joshbirk / InvoiceNegotiatorController.cls
Created December 10, 2013 19:09
Negotiator S1 Example
public class InvoiceNegotiatorController{
public Id recordId {get; set;}
public String price {get; set;}
public String quantity {get; set;}
public String priceDollar {get; set;}
public String priceCents {get; set;}
public class InvoiceList {