Skip to content

Instantly share code, notes, and snippets.

View dancinllama's full-sized avatar

James Loghry dancinllama

View GitHub Profile
@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: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: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 / 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>();
{{#each this.product.prodBean.subscriptionLabels}}
{{this}}
{{/each}}
//Iterate over a seperate array, but with same length.
//returns empty string for each subscription label, when it should return some text
{{#each this.product.prodBean.subscriptionDurations}}
{{this.product.prodBean.subscriptionLabels.[{{@index}}]}}]
{{/each}}
toolingSoapSForceCom.SessionHeader_element sessionEl = new toolingSoapSForceCom.SessionHeader_element();
sessionEl.sessionId = UserInfo.getSessionId();
toolingSoapSForceCom.SforceService service = new toolingSoapSForceCom.SforceService();
service.SessionHeader = sessionEl;
//service.endpoint_x = //Adjust this to your endpoint, if needed...
toolingSoapSForceCom.ApexCodeCoverageAggregateQueryResult queryResult = service.queryApexCodeCoverageAggregate('Select NumLinesCovered From ApexCodeCoverageAggregate');
System.debug(queryResult);
public class OpportunityTriggerHandler extends TriggerHandler {
private Map<Id, Opportunity> newOpportunityMap = new Map<Id, Opportunity>();
private Map<Id, Opportunity> oldOpportunityMap = new Map<Id, Opportunity>();
private List<Opportunity> triggerNew = new List<Opportunity>();
private List<Opportunity> triggerOld = new List<Opportunity>();
public OpportunityTriggerHandler() {
this.triggerNew = (List<Opportunity>) Trigger.new;
this.triggerOld = (List<Opportunity>) Trigger.old;
@dancinllama
dancinllama / gist:7826948
Created December 6, 2013 15:50
Schedulable class
global class MySchedulableClass implements Schedulable{
global void execute(SchedulableContext sc){
Database.execute(new MyBatchClass());
}
}
@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);
}