Skip to content

Commit

Permalink
Add Select from Set of Strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmonette committed Jun 5, 2017
1 parent d590a1d commit af9978b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/classes/Q.cls
Expand Up @@ -14,7 +14,6 @@ public class Q {
private List<QCondition> conditions = new List<QCondition>();
private List<Q> subQueries = new List<Q>();

public Q() {}
public Q(SObjectType fromType) { this.fromText = String.valueOf(fromType); }
public Q(String fromText) { this.fromText = fromText; }

Expand Down Expand Up @@ -59,7 +58,7 @@ public class Q {
}

/**
* Add fields to the SELECT statement
* Add fields to the SELECT statement from FieldSet
*/
public Q selectFields(Schema.FieldSet fs) {
for(Schema.FieldSetMember field : fs.getFields()) {
Expand All @@ -68,6 +67,16 @@ public class Q {
return this;
}

/**
* Add fields to the SELECT statement from Set of Strings
*/
public Q selectFields(Set<String> fields) {
for(String field : fields) {
this.fieldList.add(field);
}
return this;
}

/**
* Add a LIMIT statement
*/
Expand Down
13 changes: 12 additions & 1 deletion src/classes/QTest.cls
Expand Up @@ -28,7 +28,7 @@ private class QTest {
}

@isTest
static void testSelectFields() {
static void testSelectFieldsUsingFieldSet() {
String query =
new Q(Account.SObjectType)
.selectFields(SObjectType.Account.fieldSets.Example)
Expand All @@ -38,6 +38,17 @@ private class QTest {
Database.query(query);
}

@isTest
static void testSelectFieldsUsingSetString() {
String query =
new Q(Account.SObjectType)
.selectFields(new Set<String>{'CreatedById', 'Description', 'Owner.Email'})
.build();

System.assertEquals('SELECT CreatedById, Description, Owner.Email FROM Account', query);
Database.query(query);
}

@isTest
static void testAddOrders() {
String query =
Expand Down

0 comments on commit af9978b

Please sign in to comment.