Skip to content

Instantly share code, notes, and snippets.

@gbutt
gbutt / sfcomm-pendo.js
Created September 16, 2019 21:13
Pendo Configuration for Salesforce Lightning Communities
// add this script to Head Markup
(function() {
// skip loading pendo for community builder pages
if (location.hostname.indexOf('livepreview') > -1 || location.hostname.indexOf('sitepreview') > -1) {
return;
}
// load pendo
(function(apiKey){
(function(p,e,n,d,o){var v,w,x,y,z;o=p[d]=p[d]||{};o._q=[];
@gbutt
gbutt / JsonReader.cls
Created August 15, 2019 18:39
JsonReader
public class JsonReader {
public Map<String, Object> jsonMap {get; set;}
public JsonReader(Map<String, Object> jsonMap) {
this.jsonMap = jsonMap;
}
public String getString(String path) {
return (String)getFieldAtPath(path);
}
@gbutt
gbutt / retrieve-object-perms.sh
Created May 19, 2019 18:40
SFDX script to retrieve profiles and perm sets with object CRUD and FLS
#!/bin/bash
TARGET_ORG=$1
if ["$TARGET_ORG" == ""]; then
echo Please specify a target username
echo For a list of available usernames use: sfdx force:org:list
exit 1
fi
@gbutt
gbutt / TestDataFactory.cls
Last active October 6, 2018 16:15
Apex TestDataFactory
public class TestDataFactory {
public class SObjectGenerator {
public Integer seed = 0;
private Map<String,Object> fields;
private SObjectType sobType;
public SObjectGenerator(SObjectType sobType, Map<String,Object> fields) {
this.fields = fields;
}
@gbutt
gbutt / load-data.sh
Created November 30, 2017 14:53
Get Record Types for Scratch Org Data Load
#!/bin/sh
mkdir tmp
# get all record types and save to a file
sfdx force:data:soql:query --query "SELECT ID, DeveloperName, SObjectType FROM RecordType WHERE IsActive = true" > tmp/recordtypes.txt
# get record type id for account record type with developer name = Educational_Institution
RTID_ACCOUNT_INSTITUTION=`cat tmp/recordtypes.txt | awk ' $3 ~ /Account/ && $2 ~ /Educational_Institution/ { print $1 } ' `
@gbutt
gbutt / _sfdx
Created November 8, 2017 05:20
SFDX completions for oh-my-zsh
#compdef sfdx
# SFDX Autocomplete plugin for Oh-My-Zsh
# Requires: The SFDX client CLI
# Author: gbutt
# Usage: add this file to ~/.oh-my-zsh/plugins/sfdx, and then add sfdx to your plugins in ~/.zshrc
local -a _1st_arguments
_1st_arguments=(
"force\:alias\:list":"list username aliases for the Salesforce CLI"
@gbutt
gbutt / soql2csv.sh
Last active April 5, 2019 22:43
SFDX convert SOQL into CSV
#!/bin/sh -e
function printHelp() {
echo "Incorrect usage. Example:\n\t./soql2csv.sh \"SELECT Id, Name FROM Account LIMIT 10\" myorg > accounts.csv";
}
if [ ! -e "`which jq`" ]; then
echo "You need to install jq to use this script."
if [[ "`uname`" == "Darwin" && -e "`which brew`" ]]; then
echo "Try running 'brew install jq'"
@gbutt
gbutt / PharmcasImportController.cls
Last active November 24, 2020 15:24
PharmCAS download for Salesforce
/*
PharmCAS Import Controller - Used by VF Page pharmcasImport
This controller mostly offers some RemoteAction methods to our Visualforce page
Most of the Remote Actions act as proxies for web service calls to the WebAdMIT system in order to work around CORS restrictions.
e.g. initiateExport, checkExportStatus, and downloadExport
upsertApps is the main action on this controller. It will receive a list of WebAdMIT records and process them in Salesforce.
For more info on this refer to the Technical Documentation at https://docs.google.com/document/d/edit
*/
@gbutt
gbutt / LoadAngularFromLocalhost.js
Created November 8, 2016 02:26
Load angular app from localhost, and fallback to a static resource
var j$ = jQuery.noConflict();
if ({! debugEnabled }) {
loadSourcesLocalhost().fail(loadSourcesSfdc);
} else {
loadSourcesSfdc();
}
function loadSourcesLocalhost() {
return j$.ajax({url: '//localhost:3000/vendor.js', dataType: 'script', timeout: 100})
@gbutt
gbutt / TasksUpdateSalesActivity.cls
Created July 18, 2016 16:43
Apex class for updating last sales activity and next sales activity when tasks are created or updated
public with sharing class TasksUpdateSalesActivity {
public static final String STATUS_COMPLETED = 'Completed';
@TestVisible
private Task[] newLeadContactTasks {
get {
if (newLeadContactTasks == null) {
newLeadContactTasks = new Task[]{};
// process trigger.new and only return tasks associated with a lead or contact