Skip to content

Instantly share code, notes, and snippets.

@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 / ActionPollerExample.apxc
Created Nov 10, 2015
salesforce.com apex:actionPoller example
View ActionPollerExample.apxc
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 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 / Documents.apxc
Created Apr 7, 2016
Documents and Their Sizes
View Documents.apxc
public class Documents {
public Document[] getDocuments() {
return [SELECT Name, BodyLength FROM Document];
}
}
@brianmfear
brianmfear / OpportunityController.apxc
Created Apr 7, 2016
Visualforce Formula Compilation Error
View OpportunityController.apxc
public class OpportunityController {
public Opportunity[] getOpps() {
return [SELECT Name, Amount FROM Opportunity LIMIT 10];
}
}
@brianmfear
brianmfear / Obj1.trigger
Created Jun 13, 2016
Example Lock by Code
View Obj1.trigger
trigger Obj1 on Obj1 (after insert, after update) {
Obj1Trigger.handle(Trigger.new);
}
@brianmfear
brianmfear / Code39Controller.apxc
Last active Apr 15, 2019
Basic Code 39 In Visualforce
View Code39Controller.apxc
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 Jul 29, 2016
Validating a record Id in Salesforce from a String
View Utils.cls
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;
}
}
View updateContatoPonto.trigger
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 Nov 10, 2016
Five Star Rating In Visualforce
View FiveStarsController.cls
public class FiveStarsController {
public Integer rating { get; set; }
}
You can’t perform that action at this time.