Skip to content

Instantly share code, notes, and snippets.

@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())) {

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
// Regexp from https://stackoverflow.com/questions/201323/how-can-i-validate-an-email-address-using-a-regular-expression
public class Utils {
public static String[] findEmailsInString(String source) {
String emailRegex = '(?:[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*|"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])';
Pattern p = Pattern.compile(emailRegex);
Matcher m = p.matcher(source);
String[] emails = new String[0];
while(m.find()) {
emails.add(m.group(0));
}
// Randomly select A-Z, a-z, 0-9
String randomStringAllEnhanced(Integer count) {
Integer[] chars = new Integer[0],
offsets = new Integer[] { 48, 65, 97 },
mods = new Integer[] { 10, 26, 26 };
while(count > chars.size()) {
Integer rnd = Math.abs(Crypto.getRandomInteger()), cat = Math.mod(rnd, 3), seed = Math.mod(rnd, mods[cat]);
chars.add(seed+offsets[cat]);
}
return String.fromCharArray(chars);
@brianmfear
brianmfear / path.cmp
Created July 6, 2021 15:36
Custom Path Component in Aura
<aura:component >
<aura:attribute name="currentStep" type="String" />
<aura:attribute name="steps" type="String[]" />
<aura:attribute name="renderInfo" access="private" type="Object[]" />
<aura:registerEvent name="onselect" type="c:valueSelected" />
<aura:handler name="init" value="{!this}" action="{!c.update}" />
<aura:handler name="change" value="{!v.steps}" action="{!c.update}" />
@brianmfear
brianmfear / q341460.cls
Created April 26, 2021 19:55
q341460 example class v1
public class q341460 {
public String property {
get;
set;
} {
property = 'Default Property Value';
}
public final String finalProperty {
get;
@brianmfear
brianmfear / SafeNavigationOperatorCompileFail.java
Created October 28, 2020 21:28
Winter '21 Salesforce Safe Navigation Operator Bugs
// 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);
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(
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');