Just posting this because it took me a bit of time to get my answer. For anyone wanting to get a list of all the Fields present on all the FieldSets of an Object, here is my method.
Hope it will be usefull for someone day.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityprivate String getUsedFields() {
Set<String> usedFields = new Set<String>();
for (String fieldSet : Schema.SObjectType.'SObject'.fieldSets.getMap().keySet()) {
for (Schema.FieldSetMember field : Schema.SObjectType.'SObject'.fieldSets.getMap().get(fieldSet).getFields()) {
usedFields.add(field.getFieldPath());
}
}
List<String> fieldList = new List<String>(usedFields);
String fields = String.join(fieldList, ', ');
return fields;
}
Replace 'SObject in my code by the APi name of your SObject.
If you want to have duplicate, use a List instead of a set.
the String.Join() at the end is useful if you want to transform your list into a string with your values sepparated by commas to use in a Database.query like me. and you must transform your Set into a List if you want to do it.
return String.join((Iterable<String>)fieldList,', ');
For whatever reason, while you can't pass a Set
to String.join
directly, casting it is totally allowed.