Skip to content

Instantly share code, notes, and snippets.

View aidan-harding's full-sized avatar

Aidan Harding aidan-harding

  • Nebula Consulting
View GitHub Profile
<template>
<lightning-datatable
key-field="id"
columns={columns}
data={data}
hide-checkbox-column
default-sort-direction={dataTableSorter.defaultSortDirection}
sorted-direction={dataTableSorter.sortDirection}
sorted-by={dataTableSorter.sortedBy}
onsort={dataTableSorter.sortData}>
class MyClass {
constructor() {
const self = this;
Object.getOwnPropertyNames( MyClass.prototype )
.filter(name => name.indexOf('_') === 0)
.filter(name => typeof self[name] === 'function')
.forEach(function(name) {
self[name.substr(1)] = function() {
self[name].apply(self, arguments);
}
@aidan-harding
aidan-harding / rules.xml
Created August 2, 2021 10:15
XPath PMD rule to check that Salesforce custom fields contain no underscores
<?xml version="1.0"?>
<ruleset name="Salesforce Custom Rules"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>
My Salesforce rules
</description>
#!/bin/zsh
#
# Check that sfdx force:source:status is clean before committing
# Put this into .git/hooks/pre-commit
if ! sfdx force:source:status --json | jq -r '.result | length' | grep '^0$' &> /dev/null;
then
echo "Error: sfdx source is not synced with remote"
exit 1
fi
function sleeper(value) {
return new Promise(resolve => setTimeout(() => resolve(value), value * 100));
}
[5, 4, 3, 6, 1].forEach((value) => sleeper(value).then((value) => console.log(value)));
@aidan-harding
aidan-harding / AccountExclamation.cls
Last active March 8, 2021 11:10
Trigger recursion control with static variables fails with roll-backs
public with sharing class AccountExclamation implements TriggerAction.BeforeUpdate {
public void beforeUpdate(List<Account> newList, List<Account> oldList) {
for(Account thisAccount : newList) {
if(TriggerBase.idToNumberOfTimesSeenBeforeUpdate.get(thisAccount.Id) == 1 && !thisAccount.Name.endsWith('!')) {
thisAccount.Name += '!';
}
}
}
}
String jsonPayload = new YouTubeApi().getPlaylistThumbnail('playlist-id');
String thumbnailUrl = new JsonReader(jsonPayload)
.read('items[0].snippet.thumbnails.default.url'));
@aidan-harding
aidan-harding / set_behaviour.apex
Last active January 29, 2018 20:03
Strange Set Behaviour in Apex
Integer nCallsToEquals = 0;
public class HashingTest {
private String s;
public HashingTest(HashingTest ht) {
this.s = ht.s;
}
public HashingTest(String s) {