1

Controller :

public class AccountFieldSetController {
    public String queryString{get;set;}
    public List<User> accList{get;set;}
    public string user { get; set; }
    public User u { get; set; }
    public AccountFieldSetController(){

        u = new User();

        queryString = 'select id';
        for(Schema.FieldSetMember fld :SObjectType.User.FieldSets.Self_Service_My_Profile.getFields()) {
         queryString += ', ' + fld.getFieldPath();
        }
        queryString += ' from User limit 5';

        acclist = Database.query(queryString);
    }

}

VF Page:

             <apex:repeat value="{!$ObjectType.User.fieldsets.Self_Service_My_Profile}" var="fieldValue">
             <apex:inputField value="{!u[fieldValue]}" required="{!OR(fieldValue.required, fieldValue.dbrequired)}"/>
             </apex:repeat>

      </apex:pageBlockSection>

      <apex:pageBlockSection title="Account Dynamic query" collapsible="false">
          <apex:outputText value="Query is: {!queryString}" />
      </apex:pageBlockSection>

  </apex:pageblock>
</apex:form>

1

You actually don't query the current user, you get the first 5 users in your query and by doing u = new User, doesn't do anything at all. Also List<User> accList is a list of User, is that correct?

Try something like that, you should get at least your current user field based on your field set :

public AccountFieldSetController(){

    queryString = 'select id';
    for(Schema.FieldSetMember fld :SObjectType.User.FieldSets.Self_Service_My_Profile.getFields()) {
     queryString += ', ' + fld.getFieldPath();
    }
    queryString += ' from User where id = \''+Userinfo.getUserId()+'\'';

    u = Database.query(queryString);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.