Skip to content

Instantly share code, notes, and snippets.

View afawcett's full-sized avatar

Andrew Fawcett afawcett

View GitHub Profile
@afawcett
afawcett / Mock.cls
Last active April 24, 2024 10:06
Mocking SOQL result set containing sub-selects
/**
* Copyright (c), 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 / AddPicklistItemAction.cls
Last active January 4, 2023 11:47
Prototype Invocable Method wrapping the Salesforce Metadata API to allow management of Picklist Items via Process Builder and Visual Flow
/**
* Copyright (c) 2015, FinancialForce.com, inc
* 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 / 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 / AddressFinder.cmp
Last active November 25, 2022 08:58
Salesforce London World Tour 2016: Lightning Out: Components on Any Platform
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes"
controller="AddressFinderController" access="global">
<aura:attribute name="accounts" type="Account[]"/>
<aura:attribute name="contacts" type="Contact[]"/>
<aura:registerEvent name="AddressInfo" type="c:AddressInfo"/>
<div class="slds-form--stacked">
<div class="slds-form-element">
<label class="slds-form-element__label" for="inputSample2">Account Search</label>
@afawcett
afawcett / Address.cls
Last active August 12, 2022 00:25
Apex Address compound type, based on that provided in Spring'14 for Salesforce API, http://www.salesforce.com/us/developer/docs/api/Content/compound_fields_address.htm
public class Address
{
// Internally used to determine if valueOf method should read the state and country picker fields
private static Boolean stateAndCountryPickersEnabled = false;
static
{
// Are State and Country pickers enabled in this org?
Map<String, Schema.SObjectField> accountFields = Account.sObjectType.getDescribe().fields.getMap();
stateAndCountryPickersEnabled = accountFields.containsKey('BillingStateCode');
@afawcett
afawcett / CustomMetadataService.cls
Last active March 30, 2021 17:10
Custom Metadata POC for DLRS
/**
* 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 / CustomPermissionsReader.cls
Last active July 10, 2020 02:04
CustomPermissionsReader
/**
* Copyright (c), 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 / WidgetRecordEdit.cmp
Created May 30, 2017 02:15
Lightning Component for Lightning Edit Action Override
<aura:component implements="lightning:actionOverride,force:hasRecordId,force:hasSObjectName">
<aura:attribute name="record" type="Object" />
<aura:attribute name="componentRecord" type="Object" />
<aura:attribute name="recordError" type="String" />
<force:recordData
aura:id="recordLoader"
recordId="{!v.recordId}"
layoutType="FULL"
@afawcett
afawcett / README.md
Last active November 25, 2018 10:10
Apex MD API and XSLT

Requirement

Perform XSLT transform on XML returned from the Salesforce Metadata API retrieve operation (also requires unzip). Based on the code in https://github.com/financialforcedev/apex-mdapi

Solution

Adapting the metadataretrieve.page in the above repository. The original page passed the client side unzipped files from the MD retrieve zip file back to the server to add to the view state for display. As the XSLT is done client side, the above page is much simpler, the unzipped files are just handled client side and added dynamically to the page DOM.

Implementaiton Notes

  • XSLT is loaded from a static resource