Skip to content

Instantly share code, notes, and snippets.

View boxfoot's full-sized avatar

Benj boxfoot

  • Health Leads
  • Minnesota, USA
View GitHub Profile
@boxfoot
boxfoot / common.js
Created December 23, 2014 16:59
use `gulp cleanProfiles` to remove all negative (false) permissions from Salesforce permission files.
/* By Benj Kamm, bkamm@healthleadsusa.org */
// Look for the value of the first text node within the current node.
// Returns 'false' if not found, otherwise the value of the first text node in the subnode.
function getXMLNodeValue(el, key) {
var matches = el.getElementsByTagName(key);
if (!matches.length) {
return 'false';
}
return matches[0].childNodes[0].nodeValue;
@boxfoot
boxfoot / getDependentPicklists.cls (2017 approach)
Last active October 1, 2024 17:55
Handle cases where one dependent option can be used for multiple controlling options
/*
* Apex doesn't expose dependent picklist info directly, but it's possible to expose.
* Approach:
* * Schema.PicklistEntry doesn't expose validFor tokens, but they are there, and can be accessed by serializing to JSON
* (and then for convenience, deserializing back into an Apex POJO)
* * validFor tokens are converted from base64 representations (e.g. gAAA) to binary (100000000000000000000)
* each character corresponds to 6 bits, determined by normal base64 encoding rules.
* * The binary bits correspond to controlling values that are active - e.g. in the example above, this dependent option
* is available for the first controlling field only.
*
@boxfoot
boxfoot / gist:2322443
Created April 6, 2012 19:47
Determine current fiscal year in Apex
/* (c) Benj Kamm 2012
* Determine current fiscal year in Apex -- add this method to a class that needs it.
*
* FiscalYearStartMonth - Integer 1-12 corresponds to starting month of FY
* UsesStartDateAsFiscalYearName - If false, FY Name is year of ending month; if true, name from beginning month.
*/
private integer getCurrentFY() {
Organization orgInfo = [SELECT FiscalYearStartMonth, UsesStartDateAsFiscalYearName
FROM Organization