Skip to content

Instantly share code, notes, and snippets.

trigger <trigger_name> on <Object_Name> (<event_list>) {
// Trigger Logic
}
@lfreeland
lfreeland / gist:23d10b3c53d17b3349005a1801c070de
Created February 7, 2019 10:18
Account Trigger Framework Example
trigger AccountTrigger on Account (after delete, after insert, after undelete, after update, before delete, before insert, before update) {
new AccountTriggerHandler().run();
}
@lfreeland
lfreeland / gist:ef3338b8292a15dad41ddd432c5a31c8
Created February 7, 2019 10:16
Account Trigger Handler Example
public with sharing class AccountTriggerHandler extends TriggerHandlerBase {
protected override void beforeInsert(List<Sobject> newRecords) {
List<Account> newAccounts = (List<Account>) newRecords;
}
protected override void beforeUpdate(Map<Id, Sobject> oldRecordsMap, Map<Id, Sobject> newRecordsMap) {
Map<Id, Account> oldAccountsMap = (Map<Id, Account>) oldRecordsMap;
Map<Id, Account> newAccountsMap = (Map<Id, Account>) newRecordsMap;
// Do something with the Account records.
@lfreeland
lfreeland / gist:1079bbf1cb81aacdcdfd77d359b054c2
Created February 7, 2019 10:05
Simple Trigger Handler Base Class
public virtual with sharing class TriggerHandlerBase {
public void run() {
// dispatch to the correct handler method
if(Trigger.isBefore) {
if (Trigger.isInsert) {
this.beforeInsert(Trigger.New);
}
else if(Trigger.isUpdate) {
this.beforeUpdate(Trigger.oldMap, Trigger.newMap);
@lfreeland
lfreeland / gist:02c13d10ebd5873e76209891833d4c4c
Created June 29, 2018 19:40
List<Id>.Contains Salesforce Bug Apex Script Example
Id firstId = 'a0a5B000002XgIoQAK';
List<Id> ids = new List<Id>{ firstId };
Id sameId = 'a0a5B000002XgIoQAK';
// false... wtf?
system.debug(' list of ids contains same id? ' + ids.contains(sameId));
Set<Id> setOfIds = new Set<Id>{ firstId };
// true
@lfreeland
lfreeland / gist:a22735064b705a9d10dab258ad369ae1
Created April 9, 2018 03:18
Page Layout Record Display Lightning Component Usage
<c:PageLayoutRecordDislay RecordId="{! <record_id_here> }" PageLayoutName="<page_layout_api_name>" />
@lfreeland
lfreeland / gist:3b9ab50dc43125a58027c1437620d456
Created April 9, 2018 03:02
Page Layout Record Display Lightning Component Apex Controller Test Code
@isTest
public with sharing class PageLayoutRecordDisplayControllerTest {
@isTest
static void getPageLayoutMetadata_emptyPageLayoutName_expectEmptyPageLayoutTest() {
PageLayoutRecordDisplayController.PageLayout pageLayout =
PageLayoutRecordDisplayController.getPageLayoutMetadata('');
assertEmptyPageLayout(pageLayout);
}
@lfreeland
lfreeland / gist:a0f26b1fcd543dfff918c81870895fab
Created April 9, 2018 03:01
Page Layout Record Display Lightning Component Apex Controller
public class PageLayoutRecordDisplayController {
@AuraEnabled
public static PageLayout getPageLayoutMetadata(String pageLayoutName) {
List<String> componentNameList = new List<String>{pageLayoutName};
if (String.isBlank(pageLayoutName)) {
return new PageLayout();
}
List<Metadata.Metadata> layouts =
@lfreeland
lfreeland / gist:aaa5e84eba93196cca8e399fdbef5e7e
Last active September 14, 2018 19:45
Page Layout Record Display Lightning Component Design
<design:component >
<design:attribute name="PageLayoutName" label="Page Layout Name" description="The API name of the page layout." />
<design:attribute name="recordId" label="Record Id" description="The id of the record." />
<design:attribute name="sObjectName" label="Object Name" description="The Object's API name. This is required if not used on a record page." />
</design:component>
@lfreeland
lfreeland / gist:c3a6f6d340aa8165a936801b29319e73
Created April 9, 2018 02:58
Page Layout Record Display Lightning Component Helper
({
retrievePageLayout : function(component, helper) {
var action = component.get("c.getPageLayoutMetadata");
var pageLayoutName = component.get("v.PageLayoutName");
console.log("pageLayoutName: " + pageLayoutName);
var actionParams = {
"pageLayoutName" : pageLayoutName
};