I have created following method in my Opportunity selector class. I am passing my query fields dynamically from another class.
public List<Opportunity> selectByDynamicFilter(List<String> lstOfSobjectFields,String strFilter, String strRecordId){
fflib_QueryFactory query = newQueryFactory().setEnforceFLS(true).assertIsAccessible();
query.selectFields(lstOfSobjectFields);
query.setCondition(strFilter);
return (List<Opportunity>)Database.Query(query.toSOQL());
}
this is how my getSObjectFieldList method in selector looks like:
public List<Schema.SObjectField> getSObjectFieldList()
{
return new List<Schema.SObjectField>{
Opportunity.Id,
Opportunity.Name,
Opportunity.rbcpcb_LeadProductorServiceFamily__c,
Opportunity.rbcpcb_ProductCategory__c,
Opportunity.StageName,
/** API names of fields which needs to be queried */
};
}
Here is my Problem: if I pass any fields that already exist in getSObjectFieldList to my newly created method it's giving me: System.QueryException: duplicate field selected: 'fieldX'
So I Guess, it's not doing dynamic query, query adding all the fields exist in getSObjectFieldList.
Note: issue is not happening for Name field but for StageName, rbcpcb_ProductCategory__c & rbcpcb_LeadProductorServiceFamily__c.