There are times where you may need to access fieldsets in APEX to dynamically generate pages in Visualforce. In Apex, there are 2 main ways to do this, and you can select which approach you need based on what data you have available at runtime.
Scenario 1: You know the sObject and the specific name of the fieldset you need.
Scenario 2: You need to dynamically fetch specific fieldsets based on some conditions, perhaps a Custom Setting that dictates what fieldsets apply to a specific page or record type.
The following uses no concrete sObject calls in order to fetch a fieldset. You can use this if you’re dynamcially grabbing the sObject and Fieldset in a query first, and then grabbing the specific fieldset(s) to use.
Posted in Apex, Fieldsets, Salesforce.com, Tips and Time Savers, Uncategorized, VisualForce.