Skip to content

Instantly share code, notes, and snippets.

@brianmfear
brianmfear / DebugLog.txt
Last active May 1, 2024 06:21
Can anyone replicate this error?
45.0 APEX_CODE,FINEST;APEX_PROFILING,FINEST;CALLOUT,FINEST;DB,FINEST;NBA,INFO;SYSTEM,FINEST;VALIDATION,FINEST;VISUALFORCE,FINEST;WAVE,INFO;WORKFLOW,FINEST
Execute Anonymous: class kkkkkkk {
Execute Anonymous: void method1() { }
Execute Anonymous: }
Execute Anonymous: new kkkkkkk().method1();
00:25:56.1 (1554571)|USER_INFO|[EXTERNAL]|00550000000wTdS|<redacted>|(GMT-04:00) Eastern Daylight Time (America/Indiana/Indianapolis)|GMT-04:00
00:25:56.1 (1597258)|EXECUTION_STARTED
00:25:56.1 (1605985)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
00:25:56.1 (1913868)|HEAP_ALLOCATE|[72]|Bytes:3
00:25:56.1 (1984554)|HEAP_ALLOCATE|[77]|Bytes:152
@brianmfear
brianmfear / GetExtraLimitsForYourUnitTest.apxc
Last active January 11, 2024 05:09
Need more CPU or heap for creating your test data? Make it Queueable.
// Asking for extra CPU time and heap for those really "heavy" orgs
@isTest class GetExtraLimitsForYourUnitTest implements Queueable {
@testSetup static void testSetup() {
Test.startTest(); // TIP: this avoids governor limits for your @isTest methods
System.enqueueJob(new GetExtraLimitsForYourUnitTest()); // We'll get async limits!
// P.S. Did you know that the end of a unit test method triggers async code,
// just as if you called Test.stopTest()?
}
public void execute(QueueableContext context) {
// I now have 60000ms to do my setup, instead of just 10000ms.
@brianmfear
brianmfear / MonitorAsyncUsage.cls
Last active November 30, 2023 19:01
Notify Admin when approaching Async Apex usage limit
public class MonitorAsyncUsage implements Schedulable {
public class ResourceInfo {
public Integer Max;
public Integer Remaining;
}
public class LimitsAPI {
public ResourceInfo DailyAsyncApexExecutions;
}
@brianmfear
brianmfear / ExecuteAnonymous.java
Created November 27, 2023 14:55
SSCCE of running a 100k+ SOSL query
String[] objects = new String[0];
Set<String> exceptions = new Set<String> { 'caseexternaldocument' };
for(sObjectType t: Schema.getGlobalDescribe().values()) {
DescribeSObjectResult r = t.getDescribe();
if(r.isSearchable() && !exceptions.contains((''+t).toLowerCase())) {
objects.add(t+'('+string.join(r.fields.getMap().keySet(),',')+')');
}
}
String searchTerm = 'find {demo} in all fields returning '+string.join(objects,',');
System.debug(searchTerm.length());
@brianmfear
brianmfear / ExecuteAnonymous.java
Created November 26, 2023 22:14
SSCCE of running a 250k character SOQL query
// WARNING: uses lots of CPU time, set all log levels to NONE, Apex to ERROR.
String[] charset = new String[0];
for(Integer i = 48; i < 58; i++) {
charset.add(String.fromCharArray(new Integer[]{i}));
}
for(Integer i = 65; i < 91; i++) {
charset.add(String.fromCharArray(new Integer[]{i}));
}
for(Integer i = 97; i < 123; i++) {
charset.add(String.fromCharArray(new Integer[]{i}));
@brianmfear
brianmfear / StripInaccessibleAction.cls
Created November 22, 2023 02:12
Adding Security.stripInaccessible to a flow
public class StripInaccessibleAction {
public class Input {
@InvocableVariable(
description='The record to clean up'
label='Record'
required=true
)
public sObject record;
@InvocableVariable(
description='The access type to use'
@brianmfear
brianmfear / PagingSortingController.cls
Last active October 18, 2023 13:48
Lightning Paging and Sorting Demo
global class PagingSortingController {
@AuraEnabled global static Account[] getAccounts() {
return [SELECT Name, Industry, AnnualRevenue FROM Account LIMIT 1000];
}
}
global class XmlToJson {
// Try to determine some data types by pattern
static Pattern
boolPat = Pattern.compile('^(true|false)$'), decPat = Pattern.compile('^[-+]?\\d+(\\.\\d+)?$'),
datePat = Pattern.compile('^\\d{4}.\\d{2}.\\d{2}$'),
timePat = Pattern.compile('^\\d{4}.\\d{2}.\\d{2} (\\d{2}:\\d{2}:\\d{2} ([-+]\\d{2}:\\d{2})?)?$');
// Primary function to decode XML
static Map<Object, Object> parseNode(Dom.XmlNode node, Map<Object, Object> parent) {
// Iterate over all child elements for a given node
for(Dom.XmlNode child: node.getChildElements()) {
@brianmfear
brianmfear / path.cmp
Created July 6, 2021 15:36
Custom Path Component in Aura
<aura:component >
<aura:attribute name="currentStep" type="String" />
<aura:attribute name="steps" type="String[]" />
<aura:attribute name="renderInfo" access="private" type="Object[]" />
<aura:registerEvent name="onselect" type="c:valueSelected" />
<aura:handler name="init" value="{!this}" action="{!c.update}" />
<aura:handler name="change" value="{!v.steps}" action="{!c.update}" />
@brianmfear
brianmfear / AWS.cls
Last active February 8, 2023 00:14
Abstract AWS implementation in Apex Code
/*
// Example implementation as follows:
public class AWSS3_GetService extends AWS {
public override void init() {
endpoint = new Url('https://s3.amazonaws.com/');
resource = '/';
region = 'us-east-1';
service = 's3';
accessKey = 'my-key-here';
method = HttpMethod.XGET;