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
David Zhu 8David Zhu 8 

Can I get fields from custom field sets on Case object?

Hi All,
We have a custom field set on Case object. We use it to build soql query string dynamically using schema.field set class.

i.e we have field set named: CaseFieldSet. It has three fields added:  Status,Priority, and Subject. Those fields were added to CaseFieldSet in different time.

We have a requirement to get the datetime for each field added to the field set. It means we want to know what exact time of those three fields were added to CaseFieldSet.

I assume the soqy would be similar to :
select id, createddate from fieldset where name = 'CaseFieldSet'

If having no such hidden object, how can I get the date time?

Thanks,
David
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for field set.
1) http://amitsalesforce.blogspot.com/2015/02/field-sets.html

I hope that will help you
You can get field like below
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();
    }

 
David Zhu 8David Zhu 8
Thanks Amit. 
In our code, we use the similar way in your example. except using Database.query(query), we use: select ....... from case soql.
all selected fields are from field settings.

Actually, I am investigating an issue with our org. Users received an error message: Sobject row was reteieved via SOQL without querying the requested fields: Case.customfield__c.

Because users got the above error message, I suspect the cutomfield__c was not added to the field set. But I cannot recreate the issue on Sandbox after removing that field from field set. Even when user got the erroe message, it did not happen on every case. This is really haunted me. 
Any idea?

Thanks,
David