-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Nebula project (https://github.com/jongpie/NebulaFramework) has added a lot of new features for dynamic querying, but it's currently dependent on the rest of the Nebula framework. The query engine from Nebula has been ported so that it's a freestanding project that can be deployed without the rest of the framework.
- Loading branch information
Showing
81 changed files
with
3,095 additions
and
1,360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
# Apex Query Generator | ||
<a target="_blank" href="https://githubsfdeploy.herokuapp.com?owner=jongpie&repo=ApexQueryGenerator"> | ||
<a target="_blank" href="https://githubsfdeploy.herokuapp.com"> | ||
<img alt="Deploy to Salesforce" | ||
src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/src/main/webapp/resources/img/deploy.png"> | ||
</a> | ||
|
||
## Issue | ||
--Coming soon-- | ||
## Overview | ||
This is an freestanding version of the [Nebula framework's](https://github.com/jongpie/NebulaFramework/) query engine - it has been updated to remove any dependencies on the rest of the Nebula framework. | ||
|
||
## Goals | ||
The overall goal of the project is to help auto-generate dynamic SOQL for commonly used queries | ||
* Provide a structure to centralise frequently used queries for each SObject | ||
* Provide a configurable way to change the query fields, while still preventing accidental deletion of fields being used | ||
* Provide a way to create a WHERE statement as a string in Apex, while still preventing accidental deletion of fields being used | ||
|
||
## Implementation | ||
--Coming soon-- | ||
|
||
### Example Implementation: LeadQueryRepository.cls | ||
## Features | ||
The overall goal of the project is to generate dynamic SOQL & SOSL queries. Features currently include | ||
* Leverage field-level security to dynamically include fields | ||
* Dynamically include filter conditions (not possible with standard SOQL/SOSL) | ||
* Retain Salesforce's compilation-time errors for invalid fields while still taking advantage of dynamic queries - this helps avoid issues with deleting fields, misspelled field names, etc that can occur when working with strings and dynamic queries | ||
* Support for nearly all SOQL & SOSL features & keywords, including date literals, aggregate results and more | ||
* Easy-to-use query caching |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/************************************************************************************************* | ||
* This file is part of the Nebula Framework project, released under the MIT License. * | ||
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. * | ||
*************************************************************************************************/ | ||
|
||
/** | ||
* | ||
* @group Utils | ||
* | ||
* @description A utility class to help with dealing with collections (lists, sets & maps) | ||
* | ||
*/ | ||
public without sharing class CollectionUtils { | ||
|
||
/** | ||
* @description Returns the last item in a list | ||
* @param listOfItems the list to check | ||
* @return The last Object in the provided list | ||
* @example | ||
* List<String> myList = new List<String>{'A', B', 'C'}; | ||
* String lastItem = CollectionUtils.getLastItem(myList); | ||
* System.assertEquals('C', lastItem); | ||
*/ | ||
public static Object getLastItem(List<Object> listOfItems) { | ||
Integer indexOfItem = listOfItems.size() - 1; | ||
return listOfItems[indexOfItem]; | ||
} | ||
|
||
/** | ||
* @description Removes the last item in the provided list & returns the item | ||
* @param listOfItems the list to check | ||
* @return The last Object in the provided list | ||
* @example | ||
* List<String> myList = new List<String>{'A', B', 'C'}; | ||
* System.assertEquals(3, myList.size()); | ||
* String lastItem = CollectionUtils.getLastItem(myList); | ||
* System.assertEquals('C', lastItem); | ||
* System.assertEquals(2, myList.size()); | ||
*/ | ||
public static Object pop(List<Object> listToSplice) { | ||
return splice(listToSplice, listToSplice.size() - 1); | ||
} | ||
|
||
/** | ||
* @description Removes the item in the specified index from the provided list & returns the item | ||
* @param listOfItems The list to check | ||
* @param indexOfItem The index of the item to remove | ||
* @return The Object at the specified index | ||
* @example | ||
* List<String> myList = new List<String>{'A', B', 'C'}; | ||
* System.assertEquals(3, myList.size()); | ||
* String itemToRemove = CollectionUtils.splice(myList, 1); | ||
* System.assertEquals('B', itemToRemove); | ||
* System.assertEquals(2, myList.size()); | ||
*/ | ||
public static Object splice(List<Object> listToSplice, Integer indexOfItem) { | ||
Object itemToRemove = listToSplice[indexOfItem]; | ||
listToSplice.remove(indexOfItem); | ||
return itemToRemove; | ||
} | ||
|
||
/** | ||
* @description Determines if the provided input is a type of collection (list, set or map) | ||
* @param input The Object to check | ||
* @return true if the item is a type of collection, otherwise returns false | ||
* @example | ||
* List<String> myList = new List<String>{'A', 'B', 'C'}; | ||
* System.assert(CollectionUtils.isCollection(myList)); | ||
*/ | ||
public static Boolean isCollection(Object input) { | ||
return isList(input) || isSet(input) || isMap(input); | ||
} | ||
|
||
public static Boolean isList(Object input) { | ||
// If we can cast the object to a list of objects, then it's a list | ||
try { | ||
Object convertedInput = (List<Object>)input; | ||
return true; | ||
} catch(System.TypeException ex) { | ||
return false; | ||
} | ||
} | ||
|
||
public static Boolean isSet(Object input) { | ||
// We can't cast the object to a set of objects | ||
// But if we try to cast it to a list of objects & it's a set, | ||
// then a TypeException is thrown so we know it's a set | ||
try { | ||
Object convertedInput = (List<Object>)input; | ||
return false; | ||
} catch(System.TypeException ex) { | ||
return ex.getMessage().contains('Set<'); | ||
} | ||
} | ||
|
||
public static Boolean isMap(Object input) { | ||
// We can't cast the object to a map of objects | ||
// But if we try to cast it to a list of objects & it's a map, | ||
// then a TypeException is thrown so we know it's a map | ||
try { | ||
Object convertedInput = (List<Object>)input; | ||
return false; | ||
} catch(System.TypeException ex) { | ||
return ex.getMessage().contains('Map<'); | ||
} | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
src/classes/AccountRepository.cls-meta.xml → src/classes/CollectionUtils.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>38.0</apiVersion> | ||
<apiVersion>40.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
Oops, something went wrong.