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 / file.cls
Created August 1, 2022 05:29
APEX: Image content from URL
String extFileUrl = 'https://images.unsplash.com/photo-1592746455916-7ac99236b6d6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80';
Http h = new Http();
HttpRequest req = new HttpRequest();
// Replace any spaces in extFileUrl with %20
extFileUrl = extFileUrl.replace(' ', '%20');
// Set the end point URL
req.setEndpoint(extFileUrl);
req.setMethod('GET');
@lukethacoder
lukethacoder / head.css
Created June 1, 2022 07:03
Salesforce Community Error Debug Community Head Custom CSS
/* 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;
}
@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 / 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 / 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 / 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 / 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 / datetime-as-local.cls
Created January 29, 2021 06:04
APEX: Datetime as Local (SF)
Datetime.valueOfGmt(String.valueOf(Datetime.now()));
@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"
},
{