Skip to content

Instantly share code, notes, and snippets.

@brianmfear
brianmfear / AWS.cls
Last active June 19, 2024 18:36
Abstract AWS implementation in Apex Code
/*
// 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 / ActionPollerExample.apxc
Created November 10, 2015 23:59
salesforce.com apex:actionPoller example
public class ActionPollerExample implements Database.Batchable<Integer>, Iterator<Integer>, Iterable<Integer> {
Integer counter;
public Id jobId { get; set; }
public Boolean keepPolling { get; set; }
public ActionPollerExample() {
counter = 0;
keepPolling = false;
}
public Iterator<Integer> iterator() {
@brianmfear
brianmfear / Scheduled.apxc
Created March 24, 2016 03:11
Scheduled Execution bug
public class Scheduled implements Schedulable {
@TestVisible static Boolean executed = false;
public void execute(SchedulableContext c) {
executed = true;
}
}
@brianmfear
brianmfear / Documents.apxc
Created April 7, 2016 17:22
Documents and Their Sizes
public class Documents {
public Document[] getDocuments() {
return [SELECT Name, BodyLength FROM Document];
}
}
@brianmfear
brianmfear / OpportunityController.apxc
Created April 7, 2016 18:04
Visualforce Formula Compilation Error
public class OpportunityController {
public Opportunity[] getOpps() {
return [SELECT Name, Amount FROM Opportunity LIMIT 10];
}
}
@brianmfear
brianmfear / Obj1.trigger
Created June 13, 2016 17:58
Example Lock by Code
trigger Obj1 on Obj1 (after insert, after update) {
Obj1Trigger.handle(Trigger.new);
}
@brianmfear
brianmfear / Code39Controller.apxc
Last active April 15, 2019 19:41
Basic Code 39 In Visualforce
public class Code39Controller {
// Determines if the check digit should be generated
// If true, scanners must be enabled to use it
public Boolean shouldCheckDigit { get; set; }
// The source string to use. Currently only supports
// the characters in the "keys" string. Do not use '*'.
public String sourceCodeValue { get; set; }
// The index for supported characters.
static String keys = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*';
@brianmfear
brianmfear / Utils.cls
Created July 29, 2016 02:04
Validating a record Id in Salesforce from a String
public class Utils {
static Boolean validId(String recordIdString) {
try {
Id recordId = (Id)recordIdString;
String sobjectName = String.valueOf(recordId.getSObjectType());
return Database.countQuery('SELECT COUNT() FROM '+sobjectName+' WHERE Id = :recordId') > 0;
} catch(Exception e) {
return false;
}
}
trigger updateContatoPonto on Ponto__c (before insert, before update) {
Map<Integer, Id> contactsByNumber = new Map<Integer, Id>();
for(Ponto__c record: Trigger.new) {
if(record.Inscricao_Number__c != null) {
contactsByNumber.put(record.Inscricao_Numero__c.intValue(), null);
}
}
// Ignore null
contactsByNumber.remove(null);
@brianmfear
brianmfear / FiveStarsController.cls
Created November 10, 2016 00:35
Five Star Rating In Visualforce
public class FiveStarsController {
public Integer rating { get; set; }
}