Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 44814ec

Browse files
authored
Release 1.0
* New Scheduler.cls class to help simplify scheduling jobs * Created the interface ISObjectRecordTypes.cls * SObjectRepository.cls has a new constructor that will automatically add all fields to the query for the specified SObject type - essentially, it's 'select * from sobject' * Fixed a bug related to using maps & sets as query parameters * Refactored some code based on Code Climate's initial analysis (mostly in QueryDateLiteral.cls & QueryOperator.cls) * Updated README.md * Setup Code Climate * QueryBuilder.cls now has the ability to return all fields for the specified SObject type
1 parent 9c0b0cb commit 44814ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1458
-389
lines changed

.codeclimate.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
engines:
22
apexmetrics:
3-
enabled: true
3+
enabled: true
4+
config:
5+
rulesets: "./tools/codeclimate/apex/apexunit.xml,./tools/codeclimate/apex/complexity.xml,./tools/codeclimate/apex/performance.xml,./tools/codeclimate/apex/security.xml,./tools/codeclimate/apex/style.xml"
6+
enabled: true
47
ratings:
58
paths:
6-
- "src/**.cls"
7-
- "src/**.trigger"
9+
- "**.cls"
10+
- "**.trigger"

.gitattributes

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Set the default line return behavior, in case people don't have core.autocrlf set.
2+
* text=auto eol=lf
3+
4+
# Common git file types
5+
.gitattributes text eol=lf
6+
.gitignore text eol=lf
7+
*.md text eol=lf
8+
9+
# Salesforce-specfic file types
10+
*.app text eol=lf
11+
*.cls text eol=lf
12+
*.cmp text eol=lf
13+
*.component text eol=lf
14+
*.css text eol=lf
15+
*.html text eol=lf
16+
*.js text eol=lf
17+
*.page text eol=lf
18+
*.trigger text eol=lf
19+
*.xml text eol=lf

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
language: node_js
2-
32
node_js:
43
- "7"
5-
6-
script:
4+
install:
75
- npm install -g jsforce-metadata-tools
8-
- jsforce-deploy --dry-run -u $DEPLOYMENT_USERNAME -p $DEPLOYMENT_PASSWORD$DEPLOYMENT_TOKEN -D $TRAVIS_BUILD_DIR/src -l $DEPLOYMENT_LOGIN_URL --rollbackOnError true --testLevel $DEPLOYMENT_TEST_LEVEL --pollTimeout $POLL_TIMEOUT
6+
script:
7+
- jsforce-deploy --checkOnly -u $DEPLOYMENT_USERNAME -p $DEPLOYMENT_PASSWORD$DEPLOYMENT_TOKEN -D $TRAVIS_BUILD_DIR/src -l $DEPLOYMENT_LOGIN_URL --rollbackOnError true --testLevel $DEPLOYMENT_TEST_LEVEL --pollTimeout $POLL_TIMEOUT --pollInterval $POLL_INTERVAL--verbose

CNAME

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
11
# Nebula Framework for Salesforce Apex
2-
<a href="https://githubsfdeploy.herokuapp.com?owner=jongpie&repo=NebulaFramework">
3-
<img alt="Deploy to Salesforce"src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/src/main/webapp/resources/img/deploy.png">
4-
</a>
5-
6-
## Branches
7-
| Name | Build Status |
8-
| -------- | -------- |
9-
| master | <img src="https://travis-ci.org/jongpie/NebulaFramework.svg?branch=master"> |
10-
| dev | <img src="https://travis-ci.org/jongpie/NebulaFramework.svg?branch=dev"> |
2+
[![Deploy to Salesforce](https://img.shields.io/badge/salesforce-deploy-blue.svg)](https://githubsfdeploy.herokuapp.com)
3+
[![License: MIT](https://img.shields.io/badge/license-MIT-d742f4.svg)](https://opensource.org/licenses/MIT)
4+
[![Travis CI](https://img.shields.io/travis/jongpie/NebulaFramework/master.svg)](https://travis-ci.org/jongpie/NebulaFramework)
5+
[![Code Climate](https://img.shields.io/codeclimate/github/jongpie/NebulaFramework.svg)](https://codeclimate.com/github/jongpie/NebulaFramework)
6+
7+
Nebula is a development framework for Salesforce's Apex language on the Force.com platform. It aims to...
8+
1. Provide a foundation for Apex development, with the flexibility to be easily adapted to meet your implementation needs
9+
2. Promote the design of scalable, bulkified code
10+
3. Standardise how your code is written & organised
11+
4. Overcome some gaps in Apex and the Force.com platform
12+
13+
## Features
14+
Nebula focusses on streamlining how you work with SObjects
15+
1. **SObjectRepository.cls** - this module handles all DML actions & querying needs for an SObject, making the implementation of SObjects much easier & faster
16+
* **QueryBuilder.cls** powers Nebula's querying, allowing you to dynamically build reusable SOQL & SOSL queries
17+
* **SObjectRepositoryMock.cls** can be used in unit tests for test-driven development (TDD) & to drastically reduce the time of your unit tests.
18+
2. **SObjectTriggerHandler.cls** - this module provides a trigger framework to handle all trigger contexts provided by Salesforce, along with additional features like recursion prevention
19+
20+
The framework also provides several additional classes to make development easier
21+
1. **SObjectRecordTypes.cls** - record types are an important feature of the Force.com platform. Unfortunately, Apex has limitations with handling them - record types have a field called DeveloperName that (you guessed it!) should be used by developers... but native Apex describe methods cannot access this field. Nebula tries to overcome this by providing cacheable query results of record types so you can access the DeveloperName.
22+
2. **Logger.cls** - a flexible logging solution for Apex, leveraged by the framework itself
23+
3. **Environment.cls** - provides information about the current Salesforce environment
24+
4. **UUID.cls** - used to reate a randomly-generated unique ID in your code, using the Universally Unique Identifier (UUID) standard
25+
26+
## Usage
27+
Nebula uses interfaces, virtual & abstract classes and some Salesforce features (like custom settings) to provide a baseline for your own Apex development. You can deploy the latest version of Nebula to your org and build your implementation on top of it. If you want to customise how Nebula works, most classes & methods can be overridden with your own logic. Ideally, you should minimise any code changes to Nebula's classes so that you can easily upgrade in the future when new versions of Nebula are released.
28+
29+
Nebula also leverages custom settings to give you control over how the framework works within your Salesforce environment. There are 4 settings
30+
1. **Logger Settings (API Name: NebulaLoggerSettings__c)**
31+
* Enable or disable logging
32+
2. **Record Type Settings (API Name: NebulaRecordTypesSettings__c)**
33+
* Choose how record types are cached
34+
* Select if you want to include managed record types
35+
3. **Repository Settings (API Name: NebulaRepositorySettings__c)**
36+
* Automatically include common fields in your queries, like record ID, audit fields (CreatedById, CreatedDate, etc), Name field (or Subject field, where applicable) and more
37+
4. **Trigger Handler Settings (API Name: NebulaTriggerHandlerSettings__c)**
38+
* Easily disable all triggers & handlers (great for data migration and other admin tasks),
39+
* Enable or disable recursion prevention
40+
41+
## Versioning
42+
Releases are versioned using [Semantic Versioning](http://semver.org/) in the format 'v1.0.2' (MAJOR.MINOR.PATCH):
43+
44+
- MAJOR version when incompatible API changes are made
45+
- MINOR version new functionality is added in a backwards-compatible manner
46+
- PATCH version when backwards-compatible bug fixes are made

_config.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/classes/CollectionUtils.cls

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*************************************************************************************************
2+
* This file is part of the Nebula Framework project, released under the MIT License. *
3+
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
4+
*************************************************************************************************/
5+
public without sharing class CollectionUtils {
6+
7+
public static Boolean isCollection(Object input) {
8+
return isList(input) || isSet(input) || isMap(input);
9+
}
10+
11+
public static Boolean isList(Object input) {
12+
// If we can cast the object to a list of objects, then it's a list
13+
try {
14+
Object convertedInput = (List<Object>)input;
15+
return true;
16+
} catch(System.TypeException ex) {
17+
return false;
18+
}
19+
}
20+
21+
public static Boolean isSet(Object input) {
22+
// We can't cast the object to a set of objects
23+
// But if we try to cast it to a list of objects & it's a set,
24+
// then a TypeException is thrown so we know it's a set
25+
try {
26+
Object convertedInput = (List<Object>)input;
27+
return false;
28+
} catch(System.TypeException ex) {
29+
return ex.getMessage().contains('Set<');
30+
}
31+
}
32+
33+
public static Boolean isMap(Object input) {
34+
// We can't cast the object to a map of objects
35+
// But if we try to cast it to a list of objects & it's a map,
36+
// then a TypeException is thrown so we know it's a map
37+
try {
38+
Object convertedInput = (List<Object>)input;
39+
return false;
40+
} catch(System.TypeException ex) {
41+
return ex.getMessage().contains('Map<');
42+
}
43+
}
44+
45+
}
File renamed without changes.
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*************************************************************************************************
2+
* This file is part of the Nebula Framework project, released under the MIT License. *
3+
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
4+
*************************************************************************************************/
5+
@isTest
6+
private class CollectionUtils_Tests {
7+
8+
// Tests for lists
9+
@isTest
10+
static void it_should_say_that_a_list_of_strings_is_a_list_and_a_collection() {
11+
List<String> collectionToCheck = new List<String>{'A', 'B', 'C'};
12+
13+
System.assertEquals(true, CollectionUtils.isCollection(collectionToCheck));
14+
System.assertEquals(true, CollectionUtils.isList(collectionToCheck));
15+
System.assertEquals(false, CollectionUtils.isSet(collectionToCheck));
16+
System.assertEquals(false, CollectionUtils.isMap(collectionToCheck));
17+
}
18+
19+
@isTest
20+
static void it_should_say_that_a_list_of_integers_is_a_list_and_a_collection() {
21+
List<Integer> collectionToCheck = new List<Integer>{1, 2, 3};
22+
23+
System.assertEquals(true, CollectionUtils.isCollection(collectionToCheck));
24+
System.assertEquals(true, CollectionUtils.isList(collectionToCheck));
25+
System.assertEquals(false, CollectionUtils.isSet(collectionToCheck));
26+
System.assertEquals(false, CollectionUtils.isMap(collectionToCheck));
27+
}
28+
29+
@isTest
30+
static void it_should_say_that_a_list_of_users_is_a_list_and_a_collection() {
31+
List<User> collectionToCheck = [SELECT Id FROM User LIMIT 10];
32+
33+
System.assertEquals(true, CollectionUtils.isCollection(collectionToCheck));
34+
System.assertEquals(true, CollectionUtils.isList(collectionToCheck));
35+
System.assertEquals(false, CollectionUtils.isSet(collectionToCheck));
36+
System.assertEquals(false, CollectionUtils.isMap(collectionToCheck));
37+
}
38+
39+
// Tests for sets
40+
@isTest
41+
static void it_should_say_that_a_set_of_strings_is_a_set_and_a_collection() {
42+
Set<String> collectionToCheck = new Set<String>{'A', 'B', 'C'};
43+
44+
System.assertEquals(true, CollectionUtils.isCollection(collectionToCheck));
45+
System.assertEquals(true, CollectionUtils.isSet(collectionToCheck));
46+
System.assertEquals(false, CollectionUtils.isList(collectionToCheck));
47+
System.assertEquals(false, CollectionUtils.isMap(collectionToCheck));
48+
}
49+
50+
@isTest
51+
static void it_should_say_that_a_set_of_integers_is_a_set_and_a_collection() {
52+
Set<Integer> collectionToCheck = new Set<Integer>{1, 2, 3};
53+
54+
System.assertEquals(true, CollectionUtils.isCollection(collectionToCheck));
55+
System.assertEquals(true, CollectionUtils.isSet(collectionToCheck));
56+
System.assertEquals(false, CollectionUtils.isList(collectionToCheck));
57+
System.assertEquals(false, CollectionUtils.isMap(collectionToCheck));
58+
}
59+
60+
@isTest
61+
static void it_should_say_that_a_set_of_users_is_a_set_and_a_collection() {
62+
Set<User> collectionToCheck = new Set<User>([SELECT Id FROM User LIMIT 10]);
63+
64+
System.assertEquals(true, CollectionUtils.isCollection(collectionToCheck));
65+
System.assertEquals(true, CollectionUtils.isSet(collectionToCheck));
66+
System.assertEquals(false, CollectionUtils.isList(collectionToCheck));
67+
System.assertEquals(false, CollectionUtils.isMap(collectionToCheck));
68+
}
69+
70+
// Tests for maps
71+
@isTest
72+
static void it_should_say_that_a_map_of_strings_is_a_map_and_a_collection() {
73+
Map<String, Integer> collectionToCheck = new Map<String, Integer>{
74+
'First' => 1,
75+
'Second' => 2,
76+
'Third' => 3
77+
};
78+
79+
System.assertEquals(true, CollectionUtils.isCollection(collectionToCheck));
80+
System.assertEquals(true, CollectionUtils.isMap(collectionToCheck));
81+
System.assertEquals(false, CollectionUtils.isList(collectionToCheck));
82+
System.assertEquals(false, CollectionUtils.isSet(collectionToCheck));
83+
}
84+
85+
@isTest
86+
static void it_should_say_that_a_map_of_integers_is_a_map_and_a_collection() {
87+
Map<Integer, String> collectionToCheck = new Map<Integer, String>{
88+
1 => 'First',
89+
2 => 'Second',
90+
3 => 'Third'
91+
};
92+
93+
System.assertEquals(true, CollectionUtils.isCollection(collectionToCheck));
94+
System.assertEquals(true, CollectionUtils.isMap(collectionToCheck));
95+
System.assertEquals(false, CollectionUtils.isList(collectionToCheck));
96+
System.assertEquals(false, CollectionUtils.isSet(collectionToCheck));
97+
}
98+
99+
@isTest
100+
static void it_should_say_that_a_map_of_users_is_a_map_and_a_collection() {
101+
Map<Id, User> collectionToCheck = new Map<Id, User>([SELECT Id FROM User LIMIT 10]);
102+
103+
System.assertEquals(true, CollectionUtils.isCollection(collectionToCheck));
104+
System.assertEquals(true, CollectionUtils.isMap(collectionToCheck));
105+
System.assertEquals(false, CollectionUtils.isList(collectionToCheck));
106+
System.assertEquals(false, CollectionUtils.isSet(collectionToCheck));
107+
}
108+
109+
// Negative tests
110+
@isTest
111+
static void it_should_say_that_a_string_is_not_collection() {
112+
String valueToCheck = 'test string';
113+
114+
System.assertEquals(false, CollectionUtils.isCollection(valueToCheck));
115+
System.assertEquals(false, CollectionUtils.isList(valueToCheck));
116+
System.assertEquals(false, CollectionUtils.isSet(valueToCheck));
117+
System.assertEquals(false, CollectionUtils.isMap(valueToCheck));
118+
}
119+
120+
@isTest
121+
static void it_should_say_that_an_integer_is_not_collection() {
122+
Integer valueToCheck = 1;
123+
124+
System.assertEquals(false, CollectionUtils.isCollection(valueToCheck));
125+
System.assertEquals(false, CollectionUtils.isList(valueToCheck));
126+
System.assertEquals(false, CollectionUtils.isSet(valueToCheck));
127+
System.assertEquals(false, CollectionUtils.isMap(valueToCheck));
128+
}
129+
130+
@isTest
131+
static void it_should_say_that_a_user_is_not_collection() {
132+
User valueToCheck = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
133+
134+
System.assertEquals(false, CollectionUtils.isCollection(valueToCheck));
135+
System.assertEquals(false, CollectionUtils.isList(valueToCheck));
136+
System.assertEquals(false, CollectionUtils.isSet(valueToCheck));
137+
System.assertEquals(false, CollectionUtils.isMap(valueToCheck));
138+
}
139+
140+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>39.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

0 commit comments

Comments
 (0)