Skip to content

Instantly share code, notes, and snippets.

View dcarroll's full-sized avatar

Dave Carroll dcarroll

View GitHub Profile
@dcarroll
dcarroll / gist:8427394
Created January 14, 2014 22:42
Javascript operations for Visualforce Remote Objects. Totally subject to change as this feature is currently in Developer Preview until Summer '14.
/* PRE - model declaration on vf page
<apex:remoteObjects>
<apex:remoteObjectModel name="Account" fields="Id,Name" />
</apex:remoteObjects>
*/
/* INSTANCE */
// 1. W/o default properties
var acc = new SObjectModel.Account();
@dcarroll
dcarroll / GoInstant Web RTC Sample
Created February 24, 2014 20:46
Working sample of using GoInstant Web RTC Chat and Video Widget.
<!-- visStyles Static resource for CSS styles -->
.gi-override {
position: relative;
}
.webrtc-container {
position: relative;
float: left;
width: 559px;
height: 420px;
@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