Skip to content

Instantly share code, notes, and snippets.

View dancinllama's full-sized avatar

James Loghry dancinllama

View GitHub Profile
@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: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: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: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]
@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 / 1. Lightning Design System Checkbox Lightning Component (cmp)
Last active October 7, 2015 22:30
The checkboxes in the Salesforce Lightning Design System are odd ducks. They require a DOM structure that the Lightning component or aura ui:inputCheckbox tag doesn't support natively, due to the "slds-checkbox--faux" span, etc. Furthermore, the SLDS checkbox uses Ids to control the value between the faux span and the input:checkbox. I'm not sur…
<!-- LDS markup for a checkbox (https://www.lightningdesignsystem.com/components/forms/) -->
<div class="slds-form-element margintop10">
<label class="slds-checkbox" for="requiredCheckbox">
<ui:inputCheckbox aura:Id="requiredCheckbox" value="{!v.selectedFormObject.Required_On_Form__c}" />
<span class="slds-checkbox--faux" />
<span class="slds-form-element__label marginleft10">Required on Form?</span>
</label>
</div>
IF(
OR(
ISBLANK(Available_From__c)
,Available_From__c < CASE(
MOD(TODAY() - DATE( 1900, 1, 7 ), 7 ),
2, TODAY() + 2 + 4,
3, TODAY() + 2 + 4,
4, TODAY() + 2 + 4,
5, TODAY() + 2 + 4,
6, TODAY() + 1 + 4,
/**
* @description Simple invocable class (can be called via process or flow). For logging a message or messages to the debug logs.
* @author James Loghry
* @date 8/1/2016
*/
public class InvocableLogger {
@InvocableMethod
public static void log(List<String> messages){
if(messages != null){
for(String message : messages){
@dancinllama
dancinllama / Apex controller
Last active November 21, 2016 16:49
Component for displaying Contact Name(s)
/**
* ContactsCtrl
* @description Apex and stuff..
* @author
* @date 11/21/2016
*/
public with sharing class ContactsCtrl {
@AuraEnabled
public static List<Contact> getContacts(){