Skip to content

Instantly share code, notes, and snippets.

View justin-lyon's full-sized avatar

Justin Lyon justin-lyon

  • Daejeon, South Korea
View GitHub Profile
@justin-lyon
justin-lyon / recursive-queueable.java
Last active January 9, 2025 23:07
Salesforce Apex Recursive Queueable for a service that is not bulkified
public class SomeServiceQueueable implements Queueable, Database.AllowsCallouts {
private List<Case> cases;
public SomeServiceQueueable (List<Case> newCases) {
this.cases = newCases;
}
public void execute (QueueableContext ctx) {
if (!this.cases.isEmpty()) {
Case toSend = this.cases.remove(0);
public class DeviceCount {
  private Id accountId;
  private String typeName;
  private Integer count;

  public DeviceCount (Id accountId, String typeName, Integer count) {
    this.accountId = accountId;
    this.typeName = typeName;
 this.count = count;
@justin-lyon
justin-lyon / rtis.json
Created April 2, 2020 19:19
Get Record Type by Name from LWC RecordTypeInfos API
{
"012000000000000AAA":{
"available":true,
"defaultRecordTypeMapping":false,
"master":true,
"name":"Master",
"recordTypeId":"012000000000000AAA"
},
"0121k000000kYckAAE":{
"available":true,
@justin-lyon
justin-lyon / AccountHandler.cls.java
Last active March 12, 2020 11:51
POC to insert a feeditem as a guest user on salesforce
public class without sharing AccountHandler {
public static void postToChatter() {
FeedItem fi = new FeedItem(/*Add required fields*/);
insert fi;
}
@future
public static void asyncPostToChatter() {
postToChatter();
}
@justin-lyon
justin-lyon / apex.java
Created March 10, 2020 19:48
Single insert Save multiple records with relationships using External ID
// Create a guid for each record.
String guid1 = generateGuid();
String guid2 = generateGuid();
String guid3 = generateGuid();
// Assign a guid as external id to each record
Map<String, MyObject__c> objects = new Map<String, MyObject__c>();
objects.put(guid1, new MyObject(GUID__c = guid1));
objects.put(guid2, new MyObject(GUID__c = guid2));
objects.put(guid3, new MyObject(GUID__c = guid3));
@justin-lyon
justin-lyon / LoggableException.java
Last active March 11, 2020 12:36
Custom Apex error logging sample.
public virtual class LoggableException extends Exception {
private ErrorLog__c errorLog;
private List<ExceptionLog__c> exceptionLogs;
private List<RowLog__c> rowLogs;
private List<ServiceLog__c> serviceLogs;
public void init(Exception exc) {
errorLog = new ErrorLog__c();
exceptionLogs = new List<ExceptionLog__c>();
rowLogs = new List<RowLog__c>();
@justin-lyon
justin-lyon / vcs-trailhead.md
Last active March 5, 2020 21:39
Setup version control and a sandbox for a trailhead.
@justin-lyon
justin-lyon / console-output.md
Last active February 26, 2020 15:17
Getting two keyup events with weirdness happening

A single keyup event handled twice in the parent component.

once with the new value at event.detail

then again with an integer 0

keyup Lorem ipsum dolor set Lorem ipsum dolor setd

wipContainer.js:4 keyup Lorem ipsum dolor set 0

@justin-lyon
justin-lyon / sfdx-cred-cleanup.sh
Created February 21, 2020 16:53
Clean up sfdx sandbox credentials
# List out the currently registered orgs
sfdx force:org:list
# change directory to user_root/.sfdx
cd ~/.sfdx
# (windows) open directory in explorer
explorer .
# credentials are stored in .json files named for each username.
@justin-lyon
justin-lyon / psb-diff-to-deploy.sh
Created February 19, 2020 13:31
psb's diff to deploy script
#!/bin/bash
OIFS="$IFS"
IFS=$'\n'
# Salesforce deletes aura component files that were not included in the deployment. So, you have to ensure that you deploy all the files even if only 1 file in a component is changed. Eg: Even if you change just the .cmp file, you still have to deploy the controller, helper, css files, etc.
# Replace f7815723e99 with your commit id
for var in `git diff --diff-filter=ACMRT --name-only 8ef4dc2d9cf2 HEAD`;do if [[ "$var" = *"/aura/"* ]] || [[ "$var" = *"/lwc/"* ]];then tar -rf local/myfiles.tar `dirname "$var"`;else tar -rf local/myfiles.tar "$var";if [ -f "$var-meta.xml" ];then tar -rf local/myfiles.tar "$var-meta.xml";fi;fi;done
cd local
tar -xf myfiles.tar
#Uncomment these lines if you wish to package the source and deploy to an org
#cd local