Skip to content

Instantly share code, notes, and snippets.

View gitmatheus's full-sized avatar

Matheus Gonçalves gitmatheus

View GitHub Profile
// Snippet from AccountTriggerHandlerTest
...
mockDataLayer = new MockDataLayer();
mockFieldReader = new MockFieldReader();
...
// First, the formula field on the child object:
mockFieldReader.addValueToField(
mockDataLayer.childAccount,
// Snippet from the AccountTriggerHandler
...
// If the mock data is not being used
// creates new instances of the real deal
public AccountTriggerHandler() {
this(new DataLayer(), new FieldReader());
}
// Child_Accounts__r is a nonwritable child relationship
// Uses the field reader to retrieve the list of child records:
public class MockFieldReader implements IFieldReader {
// Map of value stored in a field by Id
private Map<Id, Map<String, Object>> fieldValuesByIdMap = new Map<Id, Map<String, Object>>();
// ======================================================================
// GETTERS
// The following method will try to find the field name and value
// in the map above, and return the correct value accordingly
// ======================================================================
public Object getFieldValue(SObject record, String fieldName) {
public class FieldReader implements IFieldReader {
// Retrieves a value from a field, as an object
public Object getFieldValue(SObject record, String fieldName) {
return record.get(fieldName);
}
// Retrieves a value from a field, as a SObject
public SObject getFieldRecord(SObject record, String fieldName) {
return record.getSObject(fieldName);
public interface IFieldReader {
Object getFieldValue(SObject record, String fieldName);
SObject getFieldRecord(SObject record, String fieldName);
List<SObject> getFieldRecords(SObject record, String fieldName);
}
/******************************************
Imagine three strings:
- one with a single space
- one null
- one not empty and not null
******************************************/
String singleSpaceString = ' ';
String nullString = null;
String notEmptyString = 'Samwise Gamgee is the real hero';
public class DataLayerHandler {
public interface IDataLayer {
List<Document__c> getDocumentList();
}
}
@gitmatheus
gitmatheus / Boating class STEP 1.md
Last active May 12, 2021 03:20
Boating class STEP 1

Boating class STEP 1

Captain Kevin Pisani

3 steps

  • Send a copy of my card - email to Captain Kevin or bring it to the water class
  • Class today
  • Class on Friday
public class MyUser {
public String username;
public String password;
public void validateCredentials() {
// calling an static method without creating a new instance of MySecurityClass
Boolean authenticated = MySecurityClass.validateCredentials(username, password);
System.debug('User username: ' + username);
System.debug('User Authentication: ' + authenticated);
public class MySecurityClass {
public static Boolean validateCredentials(String username, String password){
if (username == 'admin' && password == 'admin'){
return true;
} else {
return false;
}
}
}