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
javed786javed786 

how to exclude the some fields from fieldset in apex class daynamically ?

Amit Chaudhary 8Amit Chaudhary 8
PLease check below post if that will help you
1) http://amitsalesforce.blogspot.com/2015/02/field-sets.html
 
public with sharing class DynamicTabController 

{
    public List<Account> lstAccount{get;set;}
    
    public DynamicTabController()
    {
        lstAccount=new List<Account>();

                String query = 'SELECT ';
                for(Schema.FieldSetMember f : this.getFields()) 
                {
                    query += f.getFieldPath() + ', ';
                }
                query += '  Id FROM Account limit 5 ';
                System.debug('query ------>'+query );
                lstAccount = Database.query(query);        
    }

    public List<Schema.FieldSetMember> getFields() 
    {
        return SObjectType.Account.FieldSets.Account_FieldSet.getFields();
    }
}



Let us know if this will help you
 
javed786javed786
Thanks Amith.

My question is not to prepate daynamic query using field set,My Question is i have 10 fields in fieldset,i want to display only 5 fields form fieldset how to do that this in daynmically. This is my question.

We can to this hordcoding the field name like below example:

for(Schema.FieldSetMember f : this.getFields())                {
                    if(f.getFieldPath().equals('xx'))  // xx is field name
                        {
                            //some logic
                        }
 }

Any other possibilities let me know.