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
Anu Raj.ax1269Anu Raj.ax1269 

Attempt to de-reference a null object in fieldset

I am trying to get fields from Contact into fieldset. but i am not bale to get the fields properly i am getting error : Attempt to de-reference a null object

my code :

     public class DemoCtrl{

     public contact DemoCtrl { get; set; }

     public List<schema.fieldsetmember> getACTFields(){ 
             // System.debug('getField ' + Fields);     
             return getFields('contact', 'ACT');

       public static List<schema.fieldsetmember> getFields(String objectName, String fieldSetName) 

        Map<String, Schema.SObjectType> GlobalDescribeMap = Schema.getGlobalDescribe(); 
        Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(objectName);
        Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe();            
         Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName);

          System.debug('GlobalDescribeMap ' + GlobalDescribeMap);
         System.debug(' SObjectTypeObj  ' + SObjectTypeObj );
          System.debug('DescribeSObjectResultObj ' +          DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName)); 
         System.debug('fieldSetObj  ' + fieldSetObj ); 
        return fieldSetObj.getFields();        



I am getting null into DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName). Can anybody guide me what is the issue it is not getting filled. Can anybody help me to solve this out.

Jeff MayJeff May

I would debug to see what value you are passing to your static method in fieldSetName