Skip to content

Instantly share code, notes, and snippets.

View dcarroll's full-sized avatar

Dave Carroll dcarroll

View GitHub Profile
@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) {
w = createWarehouseLocation('Warehouse 1');
} else {
w = warehouse[0];
@isTest
private class TestInvoiceStatementDeletion {
static testmethod void TestDeleteInvoiceWithLineItem() {
// Create an invoice with a line item then try to delete it
Invoice__c inv = TestDataFactory.createOneInvoiceStatement(true);
Test.startTest();
Database.DeleteResult result = Database.delete(inv, false);
Test.stopTest();
// Verify invoice with a line item didn't get deleted.
System.assert(!result.isSuccess());
@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(
Name='Warehouse 1',
global class CleanUpRecords implements Database.Batchable<sObject> {
global final String query;
global CleanUpRecords(String q) {
query = q;
}
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(query);
}
public class CreateMerchandiseData {
public static void ClearMerchandiseDataBatch() {
String query = 'SELECT Id,CreatedDate FROM Merchandise__c ' +
'WHERE Id NOT IN (SELECT Merchandise__c FROM Line_Item__c)';
CleanUpRecords c = new CleanUpRecords(query);
Database.executeBatch(c);
}
public static void GenerateMerchandiseData() {
global class MyScheduler implements Schedulable {
global void execute(SchedulableContext ctx) {
// 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)';
CleanUpRecords c = new CleanUpRecords(query);
Database.executeBatch(c);
}
@dcarroll
dcarroll / _authError.cshtml
Created June 23, 2015 22:46
Unexpected Errors
@if (ViewBag.ErrorMessage == "AuthorizationRequired")
{
<p>You have to sign-in to @ViewBag.OperationName. Click <a href="@ViewBag.AuthorizationUrl" title="here">here</a> to sign-in.</p>
<p>@ViewBag.ErrorMessage</p>
}
@dcarroll
dcarroll / test
Created September 28, 2016 21:48
This is tes
'use strict';
const path = require('path');
const cmds = require('./dist/index.js');
let cmd;
let flags;
const options = JSON.parse(process.argv[2].trim());
for (let i=0, len=cmds.commands.length; i<len; i++) {
#!/bin/bash
while [ $# -gt 0 ]
do
echo $1
command=$command" "$1
shift
done
echo $command
node-debug.js <path to your toolbelt source code root>/debug.js "{ \"cmd\":\"$command\" }"