Skip to content

Instantly share code, notes, and snippets.

View shanerk's full-sized avatar
Wizards only, fools!

Shane K shanerk

Wizards only, fools!
View GitHub Profile
@shanerk
shanerk / package.xml
Last active April 23, 2025 17:04
Salesforce package.xml file to get all metadata from your org. Works great with vscode and cli.
<?xml version="1.0" encoding="UTF-8" ?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
<members>*</members>
<name>ApexComponent</name>
</types>
@shanerk
shanerk / apex_debug_log_tail.sh
Last active May 10, 2024 17:39
Apex Debug Log Tail for VSCode
#!/bin/bash
# Execute this command in VSCode terminal. Your DEBUG logs will stream into the terminal from the org.
# Very useful to see DEBUG messages when running unit tests.
sf apex tail log --color | grep 'USER_DEBUG\|FATAL_ERROR'
@shanerk
shanerk / ParseEmailHeaders.cls
Created September 13, 2019 16:39
ParseEmailHeaders.cls
public with sharing class ParseEmailHeaders {
public Map<String, String> parseEmailHeaders(String headers) {
Map<String, String> headersMap = new Map<String, String>();
List<String> rows = headers.split('\n');
for (String row : rows) {
Integer div = row.indexOf(':');
String rowKey = row.substring(0, div).trim();
String rowValue = row.substring(div + 1, row.length()).trim();
String existingValue = headersMap.get(rowKey);
if (existingValue != null) {
@shanerk
shanerk / undentBlock.js
Last active July 17, 2019 01:41
Un(in)dents a block of text (removing unwanted whitespace at the beginning of a line, but preserving desired indentation)
function undentBlock(block) {
let REGEX_INDEX = /^[ \t]*\**[ \t]+/g;
let indent = null;
block.split("\n").forEach(function (line) {
let match = line.match(REGEX_INDEX);
let cur = match !== null ? match[0].replace(/\*/g, "").length : null;
if (cur < indent || indent === null) indent = cur;
});
let ret = "";
block.split("\n").forEach(function (line) {
/**
* Checks and converts strings when they contain accounting negative format ($1,000.00)
* to standard negative format -$1,000.00
*
* @param str Input String to evaluate
*
* @return String containing converted value, or original value if there was no match found
*/
public static String toStandardNegative(String str) {
Pattern negPattern = Pattern.compile('^\\((.+)\\)$');
@shanerk
shanerk / ApexDeprecated.cls
Created April 29, 2019 16:41
Apex Packages & @deprecated Annotation
global with sharing class ApexDeprecated {
@Deprecated
global enum FOOBAR { FOO, BAR }
// Not Allowed - Deprecated FOOBAR return type illegal in global
global static FOOBAR bar(Integer ord) {
return FOOBAR.values()[ord];
}
// Allowed - Deprecated type is not exposed globally, so can still be used internal to the method
@shanerk
shanerk / DelegateApex.cls
Last active April 9, 2019 16:52
Delegation Example in Salesforce Apex
public class DelegateApex {
public interface SObjectDelegate {
List<SObject> getObject(String search);
}
public class AccountDelegate implements SObjectDelegate {
public List<SObject> getObject(String searchVar) {
List<Account> accounts = [SELECT Id, Name
FROM Account
@shanerk
shanerk / shaner.terminal
Created April 8, 2019 20:21
Awesome OSX Terminal Theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BackgroundAlphaInactive</key>
<real>0.80000000000000004</real>
<key>BackgroundColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGKyxYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKcHCBMZHSQoVSRudWxs1QkKCwwNDg8QERJcTlNDb21wb25lbnRzVU5TUkdCXE5T
@shanerk
shanerk / gitclean.sh
Created April 8, 2019 18:16
Git Script to Delete Local Branches Removed from the Remotes
# Creates alias which does the following:
# 1. Changes to master branch
# 2. Performs a fetch
# 3. Attempts to delete branches which have been removed from remote
# 4. Performs a verbose branch list
alias gitclean="git checkout master; git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done; git branch -vv"
@shanerk
shanerk / crypto.java
Last active January 4, 2019 01:45
Using Crypto in Apex for Fun and Profit
// Using Crypto for a Random string
nickname += String.valueOf(Crypto.getRandomInteger()).substring(1,7);
// Using Crypto to create a GUID
// TODO