schema.fieldsetmember in salesforce

<apex:page controller="AccountFieldSetController" tabStyle="Account">
  <apex:form >
      <apex:pageblock >        
          <apex:pageBlockSection title="Account list" collapsible="false">
             <apex:pageBlockTable value="{!accList}" var="acc">
                 <apex:repeat value="{!$ObjectType.Account.fieldsets.accountFieldSet}" var="fieldValue">
                     <apex:column value="{!acc[fieldValue]}">
                     </apex:column>
                 </apex:repeat>
             </apex:pageBlockTable>
          </apex:pageBlockSection>
           
          <apex:pageBlockSection title="Account Dynamic query" collapsible="false">
              <apex:outputText value="Query is: {!queryString}" />
          </apex:pageBlockSection>
           
      </apex:pageblock>
    </apex:form>
</apex:page>

4.14
7
Naved Ame 100 points

                                    public class AccountFieldSetController {
&nbsp;&nbsp;&nbsp;&nbsp;public String queryString{get;set;}
&nbsp;&nbsp;&nbsp;&nbsp;public List&lt;Account&gt; accList{get;set;}
&nbsp;&nbsp;&nbsp;&nbsp;public AccountFieldSetController(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queryString = 'select id';
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(Schema.FieldSetMember fld :SObjectType.Account.FieldSets.accountFieldSet.getFields()) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queryString += ', ' + fld.getFieldPath();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queryString += ' from Account limit 5';
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;acclist = Database.query(queryString);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}

4.14 (7 Votes)
0
3.7
11

                                    public static List&lt;Schema.FieldSetMember&gt; readFieldSet(String fieldSetName, String ObjectName)
{
&nbsp;&nbsp;&nbsp;&nbsp;Map&lt;String, Schema.SObjectType&gt; GlobalDescribeMap = Schema.getGlobalDescribe(); 
&nbsp;&nbsp;&nbsp;&nbsp;Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(ObjectName);
&nbsp;&nbsp;&nbsp;&nbsp;Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe();
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;//system.debug('====&gt;' + DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName));
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName);
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;//List&lt;Schema.FieldSetMember&gt; fieldSetMemberList =&nbsp;&nbsp;fieldSetObj.getFields();
&nbsp;&nbsp;&nbsp;&nbsp;//system.debug('fieldSetMemberList ====&gt;' + fieldSetMemberList);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return fieldSetObj.getFields(); 
}&nbsp;&nbsp;

3.7 (10 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source