Skip to content

Instantly share code, notes, and snippets.

@brianmfear
brianmfear / FiveStarsController.cls
Created November 10, 2016 00:35
Five Star Rating In Visualforce
public class FiveStarsController {
public Integer rating { get; set; }
}
// https://salesforce.stackexchange.com/a/376822/2984
// Efficiently checking if any fields from a list of fields have changed
public class DataUtils {
public class Change {
public String[] changedFields = new String[0];
public sObject record1, record2;
Change(String[] changedFields, sObject record1, sObject record2) {
this.changedFields = changedFields;
this.record1 = record1;
@brianmfear
brianmfear / DragDrop.app
Created February 20, 2017 16:39
Drag and Drop in Lightning (simple demo)
<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 / wSharingTest.apxc
Created February 9, 2022 17:59
Without Sharing overridden by System.runAs?
@isTest without sharing class wSharingTest {
@isTest static void test() {
Account a = new Account(Name='Name');
User u = [SELECT FIELDS(STANDARD) FROM User WHERE Id = :UserInfo.getUserId()].deepClone(false, false, false);
u.FederationIdentifier = '12345';
u.Alias = '12345678';
u.UserName += '.brian.fear';
u.CommunityNickname = '12345678';
u.ProfileId = [SELECT Id FROM Profile WHERE Name LIKE 'Standard%' LIMIT 1].Id;
System.runAs(new User(Id=UserInfo.getUserId())) {
@brianmfear
brianmfear / Logger.cls
Created April 5, 2022 10:30
Sample Logger in Apex (does not store the logs; do whatever you want here)
public class Logger {
static Pattern thePattern = Pattern.compile(
'(?i)^(?:class\\.)?([^.]+)\\.?([^\\.\\:]+)?[\\.\\:]?([^\\.\\:]*): line (\\d+), column (\\d+)$'
);
static Log__c[] logs = new Log__c[0];
static LoggingLevel controlLevel = LoggingLevel.DEBUG;
public static void addLog(String message) {
addLog(new DmlException(), controlLevel, message, null);
}
<aura:application >
<aura:attribute name="show" type="Boolean" default="false" />
<aura:if isTrue="{!v.show}">
<c:q369501c />
</aura:if>
</aura:application>
@brianmfear
brianmfear / label.app
Created February 14, 2022 20:25
Retrieve a label dynamically in LWC
<aura:application extends="force:slds">
<c:q317434 />
</aura:application>
@brianmfear
brianmfear / AWS.apxc
Last active February 3, 2022 09:47
AWS SQS Methods, in Apex Code.
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;

Save the file locally, decode with:

base64 -d -i q365527.zip.base64 > q365527.zip

Then decompress these files into a force-app/main/default/ directory.

Finally, deploy to your org:

sfdx force:source:deploy -p force-app
Download this as a ZIP file, move the files so they line up in the proper places, then deploy.
force-app/main/default/classes/StockMarketSharesWrapper.cls
force-app/main/default/classes/StockMarketSharesWrapper.cls-meta.xml
force-app/main/default/lwc/wrapperList/wrapperList.html
force-app/main/default/lwc/wrapperList/wrapperList.js
force-app/main/default/lwc/wrapperList/wrapperList.js-meta.xml
Support for question https://salesforce.stackexchange.com/q/365372/2984