From 1229ae2df7e32525a9686e60c01855b80d1fa494 Mon Sep 17 00:00:00 2001 From: Javwad Date: Wed, 22 Feb 2023 16:18:08 +0100 Subject: [PATCH] Added a decorator method to get picklist value by labels --- .../main/classes/fflib_QueryFactory.cls | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sfdx-source/apex-common/main/classes/fflib_QueryFactory.cls b/sfdx-source/apex-common/main/classes/fflib_QueryFactory.cls index 5d9b5db087d..de805bc8fae 100644 --- a/sfdx-source/apex-common/main/classes/fflib_QueryFactory.cls +++ b/sfdx-source/apex-common/main/classes/fflib_QueryFactory.cls @@ -63,6 +63,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr public Schema.SObjectType table {get; private set;} @TestVisible private Set fields; + private Set setFieldsByLabel; private String conditionExpression; private Integer limitCount; private Integer offsetCount; @@ -364,6 +365,13 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr this.conditionExpression = conditionExpression; return this; } + /** + * @param setFieldsByLabel set the picklist fields to return the value by picklist Label. + **/ + public fflib_QueryFactory setPicklistFieldsByLabel(Set setFieldsByLabel){ + this.setFieldsByLabel = setFieldsByLabel; + return this; + } /** * @returns the current value of the WHERE clause, if any, as set by {@link #setCondition} **/ @@ -727,6 +735,14 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr } result += String.join(fieldsToQuery,', '); + if(setFieldsByLabel != null && !setFieldsByLabel.isEmpty() ){ + for(String strField : fieldsToQuery){ + if(setFieldsByLabel.contains(strField)) + { + result = result.replace(strField, 'toLabel('+strField+')'); + } + } + } } if(subselectQueryMap != null && !subselectQueryMap.isEmpty()){ @@ -778,6 +794,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr .setLimit(this.limitCount) .setOffset(this.offsetCount) .setCondition(this.conditionExpression) + .setPicklistFieldsByLabel(this.setFieldsByLabel) .setEnforceFLS(this.mFlsEnforcement); Map subqueries = this.subselectQueryMap;