@@ -9,7 +9,7 @@ public abstract class SObjectRepository implements ISObjectRepository {
99 private Map <String , Schema .SObjectField > sobjectTypeFieldMap ;
1010 private Set <String > queryFields ;
1111 private String query ;
12- private Boolean addCommonQueryFields ;
12+ private Boolean shouldAddCommonFields ;
1313 private Schema.FieldSet fieldSet ;
1414 private List <String > whereClauseList ;
1515 private List <String > orderByList ;
@@ -20,16 +20,16 @@ public abstract class SObjectRepository implements ISObjectRepository {
2020 this (fieldSet , true );
2121 }
2222
23- protected SObjectRepository (Schema.FieldSet fieldSet , Boolean addCommonQueryFields ) {
24- this .fieldSet = fieldSet ;
25- this .addCommonQueryFields = addCommonQueryFields ;
23+ protected SObjectRepository (Schema.FieldSet fieldSet , Boolean shouldAddCommonFields ) {
24+ this .fieldSet = fieldSet ;
25+ this .shouldAddCommonFields = shouldAddCommonFields ;
2626
27- this .sobjectType = fieldSet .getSObjectType ();
28- this .sobjectTypeFieldMap = this .sobjectType .getDescribe ().fields .getMap ();
29- this .queryFields = new Set <String >();
30- this .whereClauseList = new List <String >();
31- this .orderByList = new List <String >();
32- this .forUpdate = false ;
27+ this .sobjectType = fieldSet .getSObjectType ();
28+ this .sobjectTypeFieldMap = this .sobjectType .getDescribe ().fields .getMap ();
29+ this .queryFields = new Set <String >();
30+ this .whereClauseList = new List <String >();
31+ this .orderByList = new List <String >();
32+ this .forUpdate = false ;
3333
3434 this .addCommonQueryFields ();
3535 this .addFieldSetMembers ();
@@ -94,24 +94,31 @@ public abstract class SObjectRepository implements ISObjectRepository {
9494 protected void doDelete (List <SObject > records ) {Database .delete (records );}
9595
9696 private void addCommonQueryFields () {
97- if (! this .addCommonQueryFields ) return ;
97+ if (! this .shouldAddCommonFields ) return ;
9898
9999 // Auto-add the common fields that are available for the SObject Type
100- List <String > commonFieldNameList = new List <String >{
100+ Set <String > commonFieldNameList = new Set <String >{
101101 ' Id' , ' CaseNumber' , ' CreatedById' , ' CreatedDate' , ' IsClosed' , ' LastModifiedById' , ' LastModifiedDate' ,
102102 ' Name' , ' OwnerId' , ' Subject' , ' RecordTypeId' , ' SystemModStamp'
103103 };
104+
104105 for (String commonFieldName : commonFieldNameList ) {
106+ // Verify that the field is available on the object being used
105107 if (! this .sobjectTypeFieldMap .containsKey (commonFieldName )) continue ;
106108
107- this .queryFields .add (commonFieldName );
109+ // Salesforce has some inconsistencies in casing for standard field names. We'll go lowercase
110+ // here and in addFieldSetMembers() to ensure the set is unique
111+ this .queryFields .add (commonFieldName .toLowerCase ());
108112 }
109113 }
110114
111115 private void addFieldSetMembers () {
112116 if (this .fieldSet == null ) return ;
113117
114- for (Schema .FieldSetMember field : this .fieldSet .getFields ()) this .queryFields .add (field .getFieldPath ());
118+ for (Schema .FieldSetMember field : this .fieldSet .getFields ()) {
119+ // Lowercase here as well to ensure strings added to the set are unique
120+ this .queryFields .add (field .getFieldPath ().toLowerCase ());
121+ }
115122 }
116123
117124 private SObjectRepository addCondition (Schema.SObjectField field , String operator , String value ) {
0 commit comments