All Projects → ipavlic → apex-utils

ipavlic / apex-utils

Licence: MIT license
Utility classes for Salesforce Apex development

Programming Languages

Apex
172 projects

Projects that are alternatives of or similar to apex-utils

apex-fp
Functional programming for Salesforce Apex
Stars: ✭ 231 (+1055%)
Mutual labels:  salesforce, apex, salesforce-developers
apex-tmLanguage
Salesforce Apex Language syntax grammar used for colorization
Stars: ✭ 27 (+35%)
Mutual labels:  salesforce, apex, salesforce-developers
R.apex
Functional utility library for Apex
Stars: ✭ 80 (+300%)
Mutual labels:  salesforce, apex, salesforce-developers
apex-mocks-stress-test
Testing out FFLib versus Crud / CrudMock
Stars: ✭ 47 (+135%)
Mutual labels:  salesforce, apex, salesforce-developers
Script.apex
Evaluate Javascript expressions in Apex
Stars: ✭ 18 (-10%)
Mutual labels:  salesforce, apex, salesforce-developers
apexmock
force.com Mock data and fixtures for Apex Unit Tests
Stars: ✭ 24 (+20%)
Mutual labels:  salesforce, apex, salesforce-developers
Apex-Code-Conventions
Apex conventions and best practices for Salesforce Developers
Stars: ✭ 28 (+40%)
Mutual labels:  salesforce, apex, salesforce-developers
NebulaFramework
A development framework for Salesforce's Apex language & the Force.com platform
Stars: ✭ 28 (+40%)
Mutual labels:  salesforce, apex, salesforce-developers
apex-rollup
Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.
Stars: ✭ 133 (+565%)
Mutual labels:  salesforce, apex, salesforce-developers
apex-dml-mocking
DML mocking, CRUD mocking, dependency injection framework for Salesforce.com (SFDC) using Apex
Stars: ✭ 38 (+90%)
Mutual labels:  salesforce, apex, salesforce-developers
spaghetti-cmd-loader
Salesforce Custom Metadata Type Loader, designed for Lightning Experience
Stars: ✭ 13 (-35%)
Mutual labels:  salesforce, salesforce-developers
ApexTriggerHandler
Another library implements Apex trigger handler design pattern.
Stars: ✭ 40 (+100%)
Mutual labels:  salesforce, apex
sf-cross-cutting-concerns
Apex Cross cutting concerns for Salesforce
Stars: ✭ 29 (+45%)
Mutual labels:  salesforce, apex
canvas-starter-kit
A template for developing on the Salesforce Canvas platform in Javascript.
Stars: ✭ 23 (+15%)
Mutual labels:  salesforce, salesforce-developers
HTTPCalloutFramework
HTTP Callout Framework - A light weight callout framework for apex HTTP callouts in Salesforce
Stars: ✭ 43 (+115%)
Mutual labels:  salesforce, salesforce-developers
ApexCallouts
A lightweight Apex library for making HTTP callouts. Works with remote site settings and named credentials.
Stars: ✭ 32 (+60%)
Mutual labels:  salesforce, apex
texei-sfdx-plugin
Texeï's plugin for sfdx
Stars: ✭ 99 (+395%)
Mutual labels:  salesforce, salesforce-developers
apex-query-builder
Convenient query builder for dynamic SOQL queries
Stars: ✭ 37 (+85%)
Mutual labels:  salesforce, apex
Salesforce-Short-Hands
The main purpose of this repository is to put all the utilities in one place so that other developers can get help and they can also contribute to this repo.
Stars: ✭ 31 (+55%)
Mutual labels:  salesforce, salesforce-developers
SFDCRules
Simple yet powerful Rule Engine for Salesforce - SFDCRules
Stars: ✭ 38 (+90%)
Mutual labels:  salesforce, apex

Apex Utilities

Classes

ApexString

ApexString is a case-insensitive String, which makes it possible to use collections which behave consistently with == operator on String.

ApexString a = 'test';
ApexString b = 'tEsT';
Boolean isOperatorEqual = a == b; // true
Boolean isEqualsEqual = a.equals(b); // *true*, unlike regular String

Set<ApexString> stringSet = new Set<ApexString>();
stringSet.add(a);
stringSet.add(b);

System.assertEquals(1, stringSet.size()); // contains just a *single* case-insensitive element, unlike regular String!
System.assert(stringSet.contains(a)); // true
System.assert(stringSet.contains(b)); // true
Modifier and type Method Description
static ApexString of(String str) Returns a case-insensitive ApexString
static List<ApexString> listOf(Iterable<String> strings) Returns a List<ApexString> which contains all strings from provided iterable
static List<ApexString> listOf(Set<String> strings) Returns a List<ApexString> which contains all strings from provided set
static Set<ApexString> setOf(Iterable<String> strings) Returns a Set<ApexString> which contains all strings from provided iterable
static Set<ApexString> setOf(Set<String> strings) Returns a Set<ApexString> which contains all strings from provided set
static String join(Iterable<ApexString> strings, String separator) Joins the strings with separator and returns the resulting String
static String join(Set<ApexString> strings, String separator) Joins the strings with separator and returns the resulting String

Warning ⚠️

System.String.join does not use the toString method on objects it is joining. All ApexString instances are therefore stringified to 'ApexString' before they are joined into the final string (for example 'ApexString,ApexString,ApexString'). To join collections of ApexString, use ApexString.join instead.

Instant

Instant enables mocking dates and datetimes in tests for classes with temporal logic, by providing Datetime.now() and Date.today() replacements. This is helpful when Date and Datetime injection is not possible or convenient.

public class TemporalExample {
    public static String timestamp() {
        return Datetime.now().format('yyyy-MM-dd\'T\'HH:mm:ss'); // relies on current datetime provided by System.Datetime
    }

    public static String testableTimestamp() {
        return Instant.now().format('yyyy-MM-dd\'T\'HH:mm:ss'); // defaults to current datetime, but can be overriden in test
    }
}

@IsTest
public class TemporalExampleTest {
    @IsTest
    public static void testTimestamp() {
        String timestamp = TemporalExample.timestamp(); // output is untestable
    }

    @IsTest
    public static void testTestableTimestamp() {
        Datetime mockDatetime = Datetime.newInstance(2000, 1, 15, 10, 30, 59);
        Instant.setNow(mockDatetime);
        String timestamp = TemporalExample.testableTimestamp();
        System.assertEquals(timestamp, '2000-01-15T10:30:59');
    }
}

Optional

Optional simplifies operations with values which can be null.

Modifier and type Method Description
static Optional of(Object value) Returns an Optional that wraps the provided value if it’s non-null. Throws a LambdaException exception otherwise
static Optional ofNullable(Object value) Returns an Optional that wraps the provided value if it’s non-null. Returns an empty Optional otherwise
static Optional empty() Returns an empty Optional
Object get() Returns a value if it’s present. Throws a LambdaException otherwise
Boolean isPresent() Returns whether the value is present.
Object orElse(Object other) Returns the value if it’s present, and provided other otherwise
Object orElseThrow(Exception providedException) Returns the value if it’s present, and throws providedException otherwise
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].