Skip to content

Instantly share code, notes, and snippets.

@brianmfear
brianmfear / PagingSortingController.cls
Last active Jan 6, 2021
Lightning Paging and Sorting Demo
View PagingSortingController.cls
global class PagingSortingController {
@AuraEnabled global static Account[] getAccounts() {
return [SELECT Name, Industry, AnnualRevenue FROM Account LIMIT 1000];
}
}
@brianmfear
brianmfear / AWS.apxc
Last active Jan 5, 2021
AWS SQS Methods, in Apex Code.
View AWS.apxc
public abstract class AWS {
// Post initialization logic (after constructor, before call)
protected abstract void init();
// XML Node utility methods that will help read elements
public static Boolean getChildNodeBoolean(Dom.XmlNode node, String ns, String name) {
try {
return Boolean.valueOf(node.getChildElement(name, ns).getText());
} catch(Exception e) {
return null;
@brianmfear
brianmfear / AWS.cls
Last active Dec 28, 2020
Abstract AWS implementation in Apex Code
View AWS.cls
/*
// Example implementation as follows:
public class AWSS3_GetService extends AWS {
public override void init() {
endpoint = new Url('https://s3.amazonaws.com/');
resource = '/';
region = 'us-east-1';
service = 's3';
accessKey = 'my-key-here';
method = HttpMethod.XGET;
@brianmfear
brianmfear / SafeNavigationOperatorCompileFail.java
Created Oct 28, 2020
Winter '21 Salesforce Safe Navigation Operator Bugs
View SafeNavigationOperatorCompileFail.java
// Example: CompileFail error on valid code
class B {
string field = 'Test';
}
B b1 = new B(), b2;
//System.TypeException: Comparison arguments must be compatible types: String, Boolean
System.assertEquals(true, b1.field != b2?.field);
View UpdateRelatedContact.trigger
trigger UpdateRelatedContact on Account (after update) {
Map<Id, Contact> contacts = new Map<Id, Contact>();
for(Integer i = 0, s = Trigger.new.size(); i < s; i++) {
Account oldRecord = Trigger.old[i], newRecord = Trigger.new[i];
if(
oldRecord.Field1 != newRecord.Field1 ||
oldRecord.Field2 != newRecord.Field2 ||
oldRecord.Field3 != newRecord.Field3
) {
contacts.put(newRecord.Id, new Contact(
@brianmfear
brianmfear / Scheduled.apxc
Created Mar 24, 2016
Scheduled Execution bug
View Scheduled.apxc
public class Scheduled implements Schedulable {
@TestVisible static Boolean executed = false;
public void execute(SchedulableContext c) {
executed = true;
}
}
@brianmfear
brianmfear / progressRing.cmp
Created Feb 23, 2018
LightningProgressRing component
View progressRing.cmp
<aura:component >
<aura:attribute name="value" type="Integer" default="0" />
<aura:attribute name="variant" type="String" />
<aura:attribute name="hasVariant" type="Boolean" access="private" default="{!false}" />
<aura:attribute name="ringClass" type="String" access="private" />
<aura:attribute name="iconName" type="String" access="private" />
<aura:attribute name="altText" type="String" access="private" />
<aura:handler name="init" value="{!this}" action="{!c.updateView}" />
@brianmfear
brianmfear / DragDrop.app
Created Feb 20, 2017
Drag and Drop in Lightning (simple demo)
View DragDrop.app
<aura:application >
<aura:attribute name="values"
type="String[]"
access="private" />
<aura:attribute name="dragid"
type="Integer"
access="private" />
<aura:handler name="init"
value="{!this}"
action="{!c.doInit}" />
@brianmfear
brianmfear / UpdateChangedFieldsController.cls
Last active Apr 17, 2020
Updating only changed fields in a standard controller
View UpdateChangedFieldsController.cls
public class UpdateChangedFieldsController {
SObject oldRecord, currentRecord;
public UpdateChangedFieldsController(ApexPages.StandardController controller) {
oldRecord = controller.getRecord().clone();
currentRecord = controller.getRecord();
}
public PageReference saveChanges() {
SObject newClone = currentRecord.getSObjectType().newSObject(currentRecord.Id);
Map<String, Object>
oldValues = oldRecord.getPopulatedFieldsAsMap(),
View AWSTranscribeExample.cls
public class AWSTranscribeExample extends AWS {
public override void init() {
endpoint = new Url('https://transcribe.us-west-2.amazonaws.com/');
resource = '/';
region = 'us-west-2';
service = 'transcribe';
accessKey = 'my-key-here';
method = HttpMethod.XPOST;
payload = Blob.valueOf('{"LanguageCode": "en-US","Media": {"MediaFileUri": "S3 audio file link"},"MediaFormat": "mp4","MediaSampleRateHertz": 44100,"TranscriptionJobName": "SampleRestJob7"}');
setHeader('x-amz-target','Transcribe.StartTranscriptionJob');