Skip to content

Instantly share code, notes, and snippets.

@lukethacoder
lukethacoder / datetime-as-local.cls
Created January 29, 2021 06:04
APEX: Datetime as Local (SF)
Datetime.valueOfGmt(String.valueOf(Datetime.now()));
@lukethacoder
lukethacoder / salesforce-session-storage.js
Last active August 6, 2021 02:59
Get an Object of sessionStorage data set by Salesforce Components. Should be able to work for localStorage too
function getSfSessionStorage() {
let sfSessionStorage = {};
// find the sessionStorage key that hold the SF data
Object.keys(sessionStorage).forEach((key) => {
if (key.includes('namespace')) {
sfSessionStorage = JSON.parse(sessionStorage[key]);
}
});
@lukethacoder
lukethacoder / apex-picklist-values.cls
Created January 7, 2021 23:27
APEX: Get a list of picklist values (PicklistEntry) objects in Apex Salesforce
List<PicklistEntry> fields = Account.SObjectType.getDescribe().fields.getMap().get('Type').getDescribe().getPicklistValues();
for (PicklistEntry picklistEntry : fields) {
System.debug(picklistEntry.getLabel() + ' with value: ' + picklistEntry.getValue());
}
@lukethacoder
lukethacoder / abn-entity-types-by-code.json
Created December 29, 2020 05:46
ABN Entity Types array with Code and Nice Name
[
{
"code": "PUB",
"label": "Australian Public Company"
},
{
"code": "PRV",
"label": "Australian Private Company"
},
{
@lukethacoder
lukethacoder / content-editable.js
Created December 23, 2020 01:42
JS - make every element on a page editable
document.querySelectorAll('*').forEach(el => el.contentEditable = true)
@lukethacoder
lukethacoder / upload-sql-db.sh
Created November 6, 2020 00:57
Upload MySQL DB via cli
mysql -u username -p database_name < file.sql
@lukethacoder
lukethacoder / communities.cls
Last active October 6, 2020 23:06
snippet to get a list of Salesforce Communities in APEX
List<Network> communities = [ SELECT Id, Name, UrlPathPrefix, Status FROM Network ];
for (Network community : communities) {
System.debug(community.Name + ': ' + community);
}
// or via Connect API
List<ConnectApi.Community> communitiesConnect = ConnectApi.Communities.getCommunities().communities;
for ( ConnectApi.Community community : communitiesConnect) {
@lukethacoder
lukethacoder / tasks.json
Last active April 27, 2023 06:16
SFDX Project VS Code Tasks. 2023 Updated to the new sf cli. based on https://gist.github.com/douglascayers/097a885727a0afe583122e9dc85dd3a7
{
"version": "2.0.0",
"tasks": [
{
"label": "SFDX: Deploy Current File",
"type": "shell",
"command": "sf",
"args": [
"project",
"deploy",
@lukethacoder
lukethacoder / settings.json
Last active May 11, 2021 00:21
Base VS Code Workspace and Tasks for SFDX projects (helps with hiding unnecessary metadata folders and adds handy vs code tasks for CRUD)
{
"search.exclude": {
"**/.localdevserver": true,
"**/.sfdx": true,
"**/node_modules": true,
"force-app\\main\\default\\aura": false,
"force-app\\main\\default\\classes": false,
"force-app\\main\\default\\lwc": false,
"force-app\\main\\default\\pages": false,
"force-app\\main\\default\\staticresources": true
@lukethacoder
lukethacoder / inverse-object-keys-and-values.ts
Created September 10, 2020 03:55
Inverse the Object keys/values
/**
* @description Inverse the Object keys/values
* @param {object} obj
*/
export function inverseObjectKeysAndValues(obj: { [key: string]: any }) {
return Object.keys(obj).reduce(
(acc, curr) => ({
...acc,
[obj[curr].toString()]: curr,
}),