Here is my apex class:

global class DataInsert {

     // property declarations

     Set<String> fields ; 

     global PageReference doInsert() {

        // other logic        

        Schema.DescribeSObjectResult objSchema = Incident__c.sObjectType.getDescribe();       
        Map<String, Schema.SObjectField> fieldMap = objSchema.fields.getMap();

        fields = new Set<String>();     
        for (String fieldName : fieldMap.keySet()){

            SObjectField sfield = fieldMap.get(fieldName);

            schema.describefieldresult dfield = sfield.getDescribe();
            if(objdlt.get(fieldName) == true) {
                if(dfield.isCustom() && String.valueOf(dfield.getSoapType()) == 'Boolean') {
                    System.debug('All Fields are selected ::::'+fields);

This is my vf page :

<apex:page sidebar="false" controller="DataInsert">
 <apex:form >

         <apex:pageBlock title="All Selected Fields ">        
           <apex:repeat value="{!fields}" var="key">            
                <apex:outputText value="{!key}"/> <br/>


But I got this error:

save error :unknown property 'DataInsert.fields'

How to resolve this error?

1 Answer 1


If you want your page to be able to iterate the collection, you need to give it a public getter. One way to do so would be:

public Set<String> getFields() { return fields; }

However, I would hesitate to use a Set for this functionality, since the order would not be very predictable. A better method might be to alphabetically sort them:

public List<String> getFields()
    List<String> sortedFields = new List<String>(fields);
    return sortedFields();

There is also a syntactic alternative to the above, which is similar to how you've declared your other properties:

public Set<String> fields { get; private set; }

If you change your declaration of the fields variable to the above, then it will become a property and be accessible by the page. Note that you do not need a public setter, and I use private set everywhere possible to clearly indicate properties which cannot be written by the page.

  • From this part i'm not getting the fields <apex:repeat value="{!fields}" var="key"> <apex:outputText value="{!key}"/> <br/> </apex:repeat>
    – siva
    Commented Apr 26, 2017 at 13:09
  • @venkat I know...you have to modify your controller. Did you try to make the suggested alterations to your code?
    – Adrian Larson
    Commented Apr 26, 2017 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .