Skip to content

Instantly share code, notes, and snippets.

View rsoesemann's full-sized avatar

Robert Sösemann rsoesemann

  • https://bit.ly/robert-gpt
  • Tübingen, Germany
  • 03:38 (UTC -12:00)
  • X @rsoesemann
View GitHub Profile
@rsoesemann
rsoesemann / WriteMetadata.java
Created February 9, 2018 08:53
How Custom Metadata should be usable in Apex
@IsTest
private class CustomMetadataInApex_Test {
@IsTest
private static void workLikeCustomObject() {
insert new ProductSetting__mdt(RelatedSObjectType__c = 'Account', DeveloperName = 'EnableFeature');
System.assertEquals(1, [SELECT COUNT() FROM ProductSetting__mdt]);
}
}
@rsoesemann
rsoesemann / DomainBuilder_Test.cls
Last active January 24, 2019 14:52
Apex DomainBuilder
@IsTest
private class DomainBuilder_Test {
@IsTest
private static void easyTestDataCreation() {
// Setup
Contact_t jack = new Contact_t().first('Ron').last('Harris');
new Account_t()
@rsoesemann
rsoesemann / Opportunities.cls
Last active April 26, 2019 07:50
(fflib) Domain classes should have no logic besides User Story-related commands
public with sharing class Opportunities extends fflib_SObjectDomain {
public Opportunities(List<Opportunity> records) {
super(records);
}
public override void onAfterInsert() {
new ApplyDefaultCurrency(recors).execute();
new CalculateRevenueForecast(records)
.andThen(new PublishLeadScore().forNew(records)).execute();
@rsoesemann
rsoesemann / Accounts.cls
Last active January 28, 2019 20:34
Logic-free trigger handler with overlap and centralized functionality
public with sharing class Accounts extends fflib_SObjectDomain {
public Accounts(List<Account> records) {
super(records);
}
public override void onAfterUpdate(Map<Id,SObject> old) {
new UnitOfWork(records)
.execute(new CheckTeamPermissions())
.execute(new EnhanceData())
@rsoesemann
rsoesemann / AnyWorkBatch.cls
Created March 12, 2019 10:53
Batch that can do every work
public class WorkBatch implements Database.Batchable<Work>, Database.Stateful {
private StateInfo state = new StateInfo();
// PUBLIC
public List<Work> start(Database.BatchableContext context) {
return new List<Work>{ new AccountWork(), new ContactWork(), new OpportunityWork() };
}
@rsoesemann
rsoesemann / ruleset.xml
Last active February 26, 2022 23:34
CustomField names need Type prefix and CamelCase
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Default ruleset used by the CodeClimate Engine for Salesforce.com Apex" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Default ruleset</description>
<rule name="CustomFieldNamingConvention" language="xml" message="Incorrectly named field" class="net.sourceforge.pmd.lang.rule.XPathRule">
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//CustomField[
@rsoesemann
rsoesemann / HttpMock.cls
Last active June 1, 2021 13:20
apex-http-mock
@IsTest
public class HttpMock implements HttpCalloutMock {
private static final String ANY_URL = null;
private Map<String, Map<String, Object>> responses = new Map<String, Map<String, Object>>();
// PUBLIC
@rsoesemann
rsoesemann / lesmiserables.json
Last active September 8, 2020 11:22
lesmiserables.json
{
"rawGraph":{
"nodes":[
{
"id":"Napoleon",
"degree":1,
"pagerank":0.005542802377608484,
"node_id":"Napoleon"
},
{
@rsoesemann
rsoesemann / ruleset.xml
Last active May 26, 2021 20:57
PMD ruleset with custom XPath rule "AvoidProductionDebugLogs"
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Default ruleset used by the CodeClimate Engine for Salesforce.com Apex" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Default ruleset for PMD/Codacy</description>
<!-- CUSTOM RULES -->
<rule name="AvoidProductionDebugLogs" language="apex" class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
message="Avoid leaving System.debug() statments in code as they negativly influence performance.">
@rsoesemann
rsoesemann / sfge-output.json
Created June 23, 2022 12:18
JSON output of Salesforce Graph Engine (SFGE)
[
{
"engine":"sfge",
"fileName":"/Users/rsoesemann/dev/projects/lma-app-cockpit/force-app/main/default/classes/SetupArchiveErrors.cls",
"violations":[
{
"ruleName":"ApexFlsViolationRule",
"severity":1,
"message":"FLS validation is missing for [READ] operation on [ArchivedAppError__b] with field(s) [dtm_ArchivedDate__c]",
"category":"Security",