Skip to content

Instantly share code, notes, and snippets.

View afawcett's full-sized avatar

Andrew Fawcett afawcett

View GitHub Profile
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 / 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',
@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 {
PermissionSet permissionSet = new PermissionSet();
permissionSet.Name='ApexTest';
permissionSet.label='Apex Test';
insert permissionSet;
ObjectPermissions objectPermission = new ObjectPermissions();
objectPermission.ParentId = permissionSet.Id;
objectPermission.SObjectType = Book_Order__c.SObjectType.getDescribe().getName();
objectPermission.PermissionsEdit = true;
objectPermission.PermissionsRead = true;
objectPermission.PermissionsDelete = true;
@afawcett
afawcett / build.xml
Created July 16, 2016 11:15
Cloud9 /src Directory Fix
<project>
<target name="cloud9.github.init">
</target>
<target name="sync.from.cloud9">
<sync todir="src/classes" verbose="true">
<fileset dir="${basedir}/classes">
<exclude name="**/.c9/**"/>
</fileset>
</sync>
@afawcett
afawcett / MyReportNotificationFlow-1.flow
Created September 26, 2016 09:25
Definition of the TaskReminder Flow
<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
<actionCalls>
<name>TaskReminder</name>
<label>TaskReminder</label>
<locationX>21</locationX>
<locationY>32</locationY>
<actionName>NewTask</actionName>
<actionType>quickAction</actionType>
<inputParameters>
public with sharing class EinsteinAction {
public class Prediction {
@InvocableVariable
public String label;
@InvocableVariable
public Double probability;
}
@InvocableMethod(label='Classify the given files' description='Calls the Einsten API to classify the given ContentVersion files.')
@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();
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(
/**
*
CustomMetadata.Operations
.callback(
// Platform event for deploy status
MetadataDeployment__e.getSObjectType(),
MetadataDeployment__e.DeploymentId__c,
MetadataDeployment__e.Result__c)
.enqueueUpsertRecords(
// Metadata record type