[SalesForce] How to get all fields set dynamically where a object

I have a Vf page where I am displaying all the objects from the current environment. I am displaying it in a selectList. I need to get all the field set which are there on the object which is been selected dynamically. Is it possible to get it there on Vf page. Please help me out to get the solution over this issue.

Best Answer

You can display a list on page which holds the names of the field sets when sobject is selected dynamically on page.

List<String> listOfFieldSetApiNames = new List<String>();
String strObjectApiName = 'Account';
Schema.SObjectType sObjType = Schema.getGlobalDescribe().get(strObjectApiName);
if( sObjType != NULL ) {
    Map<String, Schema.FieldSet> fieldSetNameToItsRecord = sObjType.getDescribe().fieldsets.getMap();
    listOfFieldSetApiNames.addAll( fieldSetNameToItsRecord.keySet() );
}

"strObjectApiName" this instance will be referred on page to hold the valid sobject api name and "listOfFieldSetApiNames" this will display the respective field sets.