Skip to content

Instantly share code, notes, and snippets.

@lukethacoder
lukethacoder / workspace-settings.json
Last active March 13, 2020 23:43
VS Code Workspace Settings
{
"folders": [
{
"path": "C:\\Github\\PROJECT_NAME"
}
],
"settings": {
"workbench.colorCustomizations": {
"titleBar.activeBackground": "#141415",
"titleBar.activeForeground": "#FFC87F",
@lukethacoder
lukethacoder / wtf-sfdx-scratch-org.md
Last active April 12, 2023 02:06
wtf-sfdx-scratch-org

How the heck do I set up a scratch org using sfdx? Well, you're in the right place.

This gist has been moved and published here

@lukethacoder
lukethacoder / url-params.js
Last active May 27, 2022 01:08
get the url params object from a search string (url string || window.location.search)
/**
* Retrieve URL params from the url
*/
export const getUrlParams = (search = window.location.search) => {
return [...new URLSearchParams(search).entries()].reduce(
(acc, [key, value]) => {
const _value = decodeURIComponent(value)
return {
...acc,
[key]: _value !== 'null' && _value !== 'undefined' ? _value : undefined,
@lukethacoder
lukethacoder / fill-array-with-number.js
Created March 13, 2020 10:33
given a number, create a new array and fill it with incrementing numbers
[...Array(10).keys()]
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
@lukethacoder
lukethacoder / aes-gcm-crypto-object-usage.js
Last active March 14, 2020 12:06
window.crypto - AES-GCM encryption feat. sessionStorage
// Encryption/decryption of an object
let encrypted = await encrypt(
{ a: 0, b: 1, c: true, d: 'foobar' },
SUPER_SECRET_PASSPHRASE
);
console.log(encrypted);
// => '["bkvTkQNfTfnP7uUirivktij4iy66pSbiBDYJ3uNChkIlDJPBdkJ4Tqbe98a+QSujoHME",[2,0,0,0,0,0,0,0]]'
let decrypted = await decrypt(encrypted, SUPER_SECRET_PASSPHRASE);
console.log(decrypted);
@lukethacoder
lukethacoder / distance-between-lon-lat.cls
Last active May 2, 2020 06:19
Apex method to check distance between to lon/lat points
List<Account> listOfAccounts = [ SELECT Id, Name, ShippingLongitude, ShippingLatitude FROM Account WHERE ShippingLatitude != NULL];
Location userLocation = Location.newInstance(-35.4330529, 149.0699176);
System.debug('a userLocation ' + userLocation);
for (Account account : listOfAccounts) {
Location placeLocation = Location.newInstance(account.ShippingLatitude, account.ShippingLongitude);
Double distanceBetween = Location.getDistance(userLocation, placeLocation, 'km');
System.debug('Distance Between ' + distanceBetween + 'km');
}
@lukethacoder
lukethacoder / salesforce-get-community-data.cls
Created May 2, 2020 06:18
Apex code to query a list of communities and their high level metadata
ConnectApi.CommunityPage queryAllTheCommunities = ConnectApi.Communities.getCommunities();
System.debug('queryAllTheCommunities ' + queryAllTheCommunities.communities);
for (ConnectApi.Community community : queryAllTheCommunities.communities) {
System.debug('--------------------------------------------------');
System.debug('id ' + community.id);
System.debug('name ' + community.name);
System.debug('description ' + community.description);
System.debug('siteUrl ' + community.siteUrl); // https://your-salesforce-sites-url.cs46.force.com/custom_site
System.debug('url ' + community.url); // /services/data/v48.0/connect/communities/0DB9A0000003eW9LWC
@lukethacoder
lukethacoder / zsh-one-dark-theme.sh
Created May 7, 2020 02:52
install zsh custom theme
curl https://raw.githubusercontent.com/benniemosher/the-one-theme/master/zsh/TheOne.zsh-theme --create-dirs -o ~/.zsh-plugins/the-one-theme/TheOne.zsh-theme
source ~/.zsh-plugins/the-one-theme/TheOne.zsh-theme
source ~/.zshrc
@lukethacoder
lukethacoder / mdapi-deploy.sh
Created May 13, 2020 00:18
Deploy Metadata API style packages using SFDX. should fire off from the same directory as your package.xml
sfdx force:mdapi:deploy -d src -u ORG_ALIAS -w 10
@lukethacoder
lukethacoder / apex-adjust-community-permissions.cls
Created May 16, 2020 04:59
APEX snippet to give the current user access to the community (will bring back the `Workspaces | Builder` buttons)
String endpoint = URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v47.0/sobjects/NetworkMemberGroup';
HttpRequest httpRequest = new HttpRequest();
httpRequest.setEndpoint(endpoint);
httpRequest.setMethod('POST');
httpRequest.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
httpRequest.setHeader('Content-Type', 'application/json;charset=UTF-8');
// Change network id and profile/permission set Id
httpRequest.setBody('{"NetworkId":"0DBB00000004d57","ParentId":"00eB0000000fegYIAQ"}');
Http http = new Http();