function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abc234Abc234 

Schema.DescribeSobjectResult has no member names fieldsets

I pass Opportunity object and opportunity field set. 

public static List<Schema.FieldSetMember> readFieldSet(String fieldSetName, String ObjectName) 
{ 

Map<String, Schema.SObjectType> GlobalDescribeMap = Schema.getGlobalDescribe(); 
Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(ObjectName); 
Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe(); 

//system.debug('====>' + DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName)); 

Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName); 

//List<Schema.FieldSetMember> fieldSetMemberList = fieldSetObj.getFields(); 
//system.debug('fieldSetMemberList ====>' + fieldSetMemberList); 
return fieldSetObj.getFields(); 
}

SurekaSureka
Hi,

Code is perfectly fine. Create field sets in the corresponding object and try passing appropriate field sets name.

Thanks
Abc234Abc234

Hi,

 

Thanks for your help.

 

Abc234Abc234

Hi Sureka,

 

Can you provide a sample code to elaborate and explain the below comment?

 

Thanks

SurekaSureka
Hi,

I tried your code and its working fine. I passed the following variables - readFieldSet('SampleFieldSet1', 'Opportunity'');

SampleFieldSet1 is the name of the field set in my opportunity object.

public static List<Schema.FieldSetMember> readFieldSet(String fieldSetName, String ObjectName)
{

Map<String, Schema.SObjectType> GlobalDescribeMap = Schema.getGlobalDescribe();
Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(ObjectName);
Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe();

system.debug('====>' + DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName)); - This statement is correctly printing the field set variable.

}

Thanks