Skip to content

Instantly share code, notes, and snippets.

View dancinllama's full-sized avatar

James Loghry dancinllama

View GitHub Profile
@dancinllama
dancinllama / gist:8f789e759dda1ce0a883
Created January 16, 2015 21:18
Thou shalt not put queries in loops (good example)
List<Account> accList = new List<Account>(
[Select
Id
,Name
,(Select
Email
From
Contacts
)
From Account]
@dancinllama
dancinllama / gist:354ade4c7ec79573ed90
Created January 16, 2015 21:11
Thou shalt not put queries in for loops (Bad example)
List<Account> accList = new List<Account>([Select Id,Name From Account]);
for(Account acc : accList){
Integer numWithEmail = 0;
for(Contact cont : [Select Id,Email From Contact Where AccountId = :acc.Id]){
if(!String.isEmpty(cont.Email)){
numWithEmail++;
}
}
}
@dancinllama
dancinllama / gist:70919d333c3db177485c
Last active November 26, 2021 02:30
Example of utilizing relationships to keep SOQL outside of a loop
List<Account> accList = new List<Account>(
[Select
Id
,Name
,(Select
Email
From
Contacts
)
From Account]
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Apex Replay Debugger",
"type": "apex-replay",
"request": "launch",
"logFile": "${command:AskForLogFileName}",
@dancinllama
dancinllama / 1st commandment - Keep thy code stupid simple - bad example
Created January 16, 2015 20:51
Keep thy code stupid simple (KISS) - bad example
public boolean isTrue(boolean myBool){
if(myBool){
return true;
}else{
return false;
}
}
public Map<Id,Contact> getContactMap(){
Map<Id,Contact> contactMap = new Map<Id,Contact>();
@dancinllama
dancinllama / gist:f90d1a21100a81c5caa3
Created January 16, 2015 20:56
Keep thy code stupid simple (KISS) - good example
public boolean isTrue(boolean myBool){
return myBool;
}
public Map<Id,Contact> getContactMap(){
return new Map<Id,Contact>([Select Id From Contact]);
}
@dancinllama
dancinllama / gist:2bfa01a863caa128cb91
Created January 16, 2015 22:23
SOQL parent relationship query
List<Account> parentAccounts = new List<Account>();
for(Contact contactWithAccountInfo : [Select Name,Account.Name,Account.AnnualRevenue From Contact]){
System.debug('Contact Account Id: ' + contactWithAccountInfo.Account.Id);
parentAccounts.add(contactWithAccountInfo.Account);
}
@dancinllama
dancinllama / gist:6581945
Last active November 25, 2019 15:54
Using Kevin 080's trigger handler setup for kicking off batch jobs based on data load
protected override void afterInsert() {
boolean isSuccessfulRun = false;
for(Integer i=0; i < Trigger.new.size() && isSuccessful == false; i++){
isSuccessfulRun |= (((DL__c)Trigger.new.get(i)).Status__c == 'Completed');
}
if(isSuccessfulRun){
//Kick off batch jobs
Database.executeBatch(new MyNotSoFirstBatchJob(),50);
}
{
"type": "browser-preview",
"request": "attach",
"name": "Browser Preview: Attach"
},
{
"type": "browser-preview",
"request": "launch",
"name": "Browser Preview: Launch",
"url": "http://localhost:3333"
@dancinllama
dancinllama / gist:99ebc1c9afeb5d1243920552f0d7ed08
Created December 19, 2018 03:51
Loading moment.js in a LWC
import { LightningElement } from 'lwc';
import moment from '@salesforce/resourceUrl/moment';
import { loadScript } from 'lightning/platformResourceLoader';
export default class MomentStuffs extends LightningElement {
renderedCallback(){
Promise.all([
loadScript(this, moment + '/moment.js')
]).then(() => {