Skip to content

Instantly share code, notes, and snippets.

View jongpie's full-sized avatar
☁️

Jonathan Gillespie jongpie

☁️
View GitHub Profile
@jongpie
jongpie / LoggerRestResource.cls
Last active July 25, 2024 21:55
Nebula Logger - managed package REST resource prototype
@RestResource(urlMapping='/logger/*')
global class LoggerRestResource {
public class LogRequest {
public String parentLogTransactionId;
public List<LogEntryRequest> logEntries = new List<LogEntryRequest>();
}
public class LogEntryRequest {
public String loggingLevel;
public String message;
@jongpie
jongpie / UniqueIdBenchmarkingTests.cls
Created January 30, 2024 00:23
Apex - Unique ID Generation Benchmarks
@IsTest
private class UniqueIdBenchmarkingTests {
@IsTest
static void ulidBenchmark() {
Long ulidStartTime = System.now().getTime();
System.debug('ULID generation start: ' + System.now().getTime());
for (Integer i = 0; i < 1000; i++) {
ULID.generate();
}
Long ulidStopTime = System.now().getTime();
@jongpie
jongpie / listView.cmp
Created January 5, 2023 21:04
Community Cloud list view component
<aura:component implements="forceCommunity:availableForAllPageTypes" access="global">
<!-- Attributes -->
<aura:attribute access="public" required="true" name="objectApiName" type="String" />
<aura:attribute access="public" required="true" name="listName" type="String" />
<aura:attribute access="public" required="true" name="rows" type="Integer" default="50" />
<aura:attribute access="public" required="false" name="showSearchBar" type="Boolean" default="false" />
<aura:attribute access="public" required="false" name="showActionBar" type="Boolean" default="false" />
<aura:attribute access="public" required="false" name="showRowLevelActions" type="Boolean" default="false" />
<aura:attribute access="public" required="false" name="enableInlineEdit" type="Boolean" default="false" />
@jongpie
jongpie / CustomNebulaLoggerMapping.cls
Created September 14, 2022 19:11
Nebula Logger - custom field mapping
public without sharing class CustomNebulaLoggerMapping {
@InvocableMethod
public static void mapCustomFields(List<Nebula__LogEntryEvent__e> events) {
// Build up the list of event UUIDs
List<String> eventUuids = new List<String>();
for (Nebula__LogEntryEvent__e event : events) {
eventUuids.add(event.EventUuid);
}
@jongpie
jongpie / ApexExecutionOverlayLogger.cls
Last active September 14, 2022 15:58
Nebula Logger - Apex Execution Overlay prototype
public without sharing class ApexExecutionOverlayLogger {
private static final String ORG_BASE_DOMAIN = Url.getOrgDomainUrl()?.toExternalForm();
// TODO get API version dynamically
// private static final String DESCRIBE_ENDPOINT = ORG_BASE_DOMAIN + '/services/data/v55.0/tooling/sobjects/ApexExecutionOverlayAction/describe';
private static final String QUERY_ENDPOINT = ORG_BASE_DOMAIN + '/services/data/v55.0/tooling/query/?q=';
private static final String ACTION_RECORD_CREATION_ENDPOINT = ORG_BASE_DOMAIN + '/services/data/v55.0/tooling/sobjects/ApexExecutionOverlayAction';
// TODO implement batchable?
public ApexExecutionOverlayLogger() {
@jongpie
jongpie / email.md
Created April 6, 2022 16:41
That one time in 2015 that I shared my thoughts on SOQL vs SQL with James Simone

Hey James,

I just realized we haven’t discussed how to query SF data in any of our SF/Skuid trainings, and you might want to do so while I’m out this week (or you may just be curious about how it works). We can discuss this more in person if you want, but there are a couple of things to know about querying in Salesforce (spoiler alert: prepare to be sad).

Overview

  • Salesforce’s custom implementation of SQL is called SOQL – Salesforce Object Query Language.

  • It takes everything you love about SQL, throws 75% of it out the window and then burns the rest, leaving you with the sad, charred remnants of a once beautiful thing.

@jongpie
jongpie / Example_usage.cls
Created February 16, 2022 22:55
Handle (some of) the annoyances of working with SObjects
Account acct = [SELECT Id, Name, CreatedDate FROM Account LIMIT 1];
Datetime fakeCreatedDate = System.now();
List<Contact> contacts = [SELECT Id, LastName, AccountId FROM Contact LIMIT 5];
acct = (Account) new SObjectAnnoyanceHelper(acct)
.setReadOnlyField(Schema.Account.CreatedDate, fakeCreatedDate)
.appendChildren(contacts, 'Contacts')
.getRecord();
System.debug('The updated account: ' + acct);
System.debug('The new CreatedDate: ' + acct.CreatedDate);
@jongpie
jongpie / MultiQueryExampleBatchJob.cls
Last active February 20, 2022 13:55
Example Apex batch job that runs multiple queries for different SObject Types
public without sharing class MultiQueryExampleBatchJob implements Database.Batchable<SObject>, Database.Stateful {
private Schema.SObjectType currentSObjectType;
// Add any SObject Types here if you want the batch job to query them
private List<Schema.SObjectType> sobjectTypes = new List<Schema.SObjectType>{ Schema.Account.SObjectType, Schema.Contact.SObjectType };
public Database.QueryLocator start(Database.BatchableContext context) {
this.currentSObjectType = this.sobjectTypes.remove(0);
return this.getQueryLocator();
}
@jongpie
jongpie / PackageSubscriberMetrics.cls
Created September 15, 2021 19:43
Package Subscriber Metrics
public class PackageSubscriberMetrics {
public class SubscriberOrgSummary {
public Id parentOrgId;
public String subscriberName;
public Boolean installedInParentOrg = false;
public Integer numberOfOrgs = 0;
public List<SubscriberOrgDetails> subscriberOrgDetails = new List<SubscriberOrgDetails>();
}
public class SubscriberOrgDetails {
@jongpie
jongpie / FieldNamesScript.cls
Last active September 21, 2022 02:49 — forked from Feldstrom/LayoutDescriber.cls
Apex script for pulling field names from specific page layouts
public String objectName = ''; //example 'Case'
public String layoutName = ''; //example: 'Case Layout'
new LayoutDescriber().run(objectName, layoutName);
// In anonymous Apex, you can define & run a class.
// In this script, using a class ensures all describe methods work, regardless of field-level security (FLS)
public without sharing class LayoutDescriber {
public void run(String objectName, String layoutName) {
layoutName = objectName + '-' + layoutName;