Skip to content

Instantly share code, notes, and snippets.

View lukethacoder's full-sized avatar
🤔
working on non-code projects

Luke Secomb lukethacoder

🤔
working on non-code projects
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / datetime-as-local.cls
Created January 29, 2021 06:04
APEX: Datetime as Local (SF)
Datetime.valueOfGmt(String.valueOf(Datetime.now()));
@lukethacoder
lukethacoder / get-time-between-two-dates.cls
Created January 29, 2021 06:10
APEX: Get time between two Datetime instances
Long dt1Long = DateTime.now().addDays(-1).getTime();
Long dt2Long = DateTime.now().getTime();
Long milliseconds = dt2Long - dt1Long;
Long seconds = milliseconds / 1000;
Long minutes = seconds / 60;
Long hours = minutes / 60;
Long days = hours / 24;
@lukethacoder
lukethacoder / files-to-root.cmd
Created March 21, 2021 09:54
Windows CMD: Pull all files from sub folders into root folder
for /r %d in (*) do copy "%d" "C:\Documents\PATH\TO\SOURCE"
@lukethacoder
lukethacoder / community-head-dev.css
Created May 25, 2021 05:23
Show the hidden aura based errors within a Salesforce Community (errors are never logged to the console)
/* Allows devs to see errors that probably should be logged to the console but aren't */
.auraErrorBox {
width: 100%;
}
.auraErrorBox > span {
display: flex;
align-items: center;
font-weight: 700;
margin-bottom: 8px;
}