Skip to content

Instantly share code, notes, and snippets.

View afawcett's full-sized avatar

Andrew Fawcett afawcett

View GitHub Profile
@afawcett
afawcett / RemoteObjectsDemo.page
Last active August 4, 2017 13:58
Demo of Visualforce Remote Objects vs Remote Actions for blog post on the pros and cons
<apex:page controller="RemoteObjectDemoController">
<apex:remoteObjects >
<apex:remoteObjectModel name="WorkOrder__c" fields="Id,Name,AccountName__c,Cost__c"/>
<apex:remoteObjectModel name="WorkOrderLineItem__c" fields="Id,Name,Description__c,Hours__c,WorkOrder__c"/>
</apex:remoteObjects>
<script>
function doSomethingJS(answer)
{
// Create work order
var workOrder = new SObjectModel.WorkOrder__c();
@afawcett
afawcett / MetadataService.cls
Last active January 1, 2016 06:59
Spring'14 Metadata API MetadataService.cls and MetadataServiceExamples.cls
//Generated by wsdl2apex
public class MetadataService {
public class listMetadataResponse_element {
public MetadataService.FileProperties[] result;
private String[] result_type_info = new String[]{'result','http://soap.sforce.com/2006/04/metadata',null,'0','-1','false'};
private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/2006/04/metadata','true','false'};
private String[] field_order_type_info = new String[]{'result'};
}
public class FieldOverride {
@afawcett
afawcett / gist:8090245
Created December 23, 2013 00:41
Apex script for parsing and updating generated WSDL2Apex from Metadata API WSDL, uses Tooling REST API to dynamically create the modified code.
public with sharing class MetadataServicePatcher {
// Perhaps parse these from the WSDL in the future
private static final Map<String, String> METADATA_TYPES =
new Map<String, String> {
'CustomSite' => 'Metadata',
'InstalledPackage' => 'Metadata',
'CustomField' => 'Metadata',
'FieldSet' => 'Metadata',
'PicklistValue' => 'Metadata',
public with sharing class AssertCallback {
private static Map<Type, IAssertCallback> callbacks = new Map<Type, IAssertCallback>();
public interface IAssertCallback
{
void assert(String location, Object state);
}
public static void assert(Type stateType, String location, Object state)
@afawcett
afawcett / BatchWorker.cls
Last active December 29, 2022 17:12
Sample code from
/**
* Copyright (c) 2013, Andrew Fawcett
* All rights reserved.
*
* Redistribution and use 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,
@afawcett
afawcett / ant-salesforce.xml
Last active December 29, 2022 17:11
Defines some macros around sf:deploy to install and uninstall packages.
<!-- TODO: Review Ant v1.8 local properties -->
<project xmlns:sf="antlib:com.salesforce">
<!-- Download from Salesforce Tools page under Setup -->
<typedef
uri="antlib:com.salesforce"
resource="com/salesforce/antlib.xml"
classpath="${basedir}/lib/ant-salesforce.jar"/>
<!-- Download from http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ -->
@afawcett
afawcett / TestA.cls
Created May 5, 2013 14:47
Reproduction of Salesforce code coverage bug.
public class TestA {
public TestA()
{
}
public class TestB
{
public Integer doSomething()
{
Integer x = 1;
global class myClass
{
global class wrapperClass
{
public String name {get; set;}
public Account account {get; set;}
public wrapperClass()
{
account = new Account();
public with sharing class ValidationController
{
private ApexPages.StandardController standardController;
public ValidationController(ApexPages.StandardController standardController)
{
// Configure fields to query and valid (alternative to SOQL)
this.standardController = standardController;
if(!Test.isRunningTest())
this.standardController.addFields(
public with sharing class SessionController {
public List<Session__c> lstSessions {get;set;}
public SessionController()
{
lstSessions = [select Id, Session_Status__c, GL_Department__c, Quantity__c, Unit_Cost__c from Session__c];
}
public PageReference createNewSession()