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
tdeptdep 

Allow users to choose fields for edit form

Hi,

 

I am currently in the process of building a custom ui which allows for mass edit of records from a resultset.

 

I currently have the edit form wrapped in a DataTable and all fields are hard-coded.

 

My question is: Is there a way to setup a way to allow users to select which fields they will be editting?

 

I am not sure if DataTable is the correct approach to this. Everything is working in terms of hard code, but I wanted to know if there is something more dynamic.

 

Ideal situation: User gets a selection criteria (like the old report editting pages were setup, checkbox per field to display) then click next to get to the edit form containing only the fields they selected.

 

 

Thanks,

Best Answer chosen by Admin (Salesforce Developers) 
Abhinav GuptaAbhinav Gupta

No you don't need a standard controller for use of fieldset. And for the error, you are trying to use dynamic binding with a list of records, it should be with one of them only i.e. projresults is a collection, you can never get a field value out of a collection, it should be single record

This code should work:

<apex:repeat value="{!projresults}" var="projRes">
  <apex:repeat value="{!$ObjectType.TW_Project__c.FieldSets.Test}" var="f">
              <apex:outputText value="{!projRes[f]}" /> <br />
  </apex:repeat>
</apex:repeat>

 

All Answers

Abhinav GuptaAbhinav Gupta

Field Sets seems to be solution for this, please have a look at the official docs here : http://www.salesforce.com/us/developer/docs/pages/Content/pages_dynamic_vf_field_sets.htm

r1985r1985

Hi,

 

For your requirement, you can use wrapper class so that you can display radiobuttons infront of all records. User can select the records and can edit those. Wrapper class helps you to identify the selected records. Check the below link to know how to use it.

http://wiki.developerforce.com/page/Wrapper_Class

 

Thanks,

MVP

tdeptdep

Can these fieldsets be used on custom objects? I haven't come across any info for it yet. EDIT: Found it under the custom object page

 

Our system is built completely out of custom objects (2x main objects for tracking per client) - we do operate as a normal SFDC environment (Opps, Leads, etc.)

 

Also, For the post above about the wrapper class. I believe I have achieved what this is showing. Correct me if I am wrong but that is for selecting which records you would want to update? If so, that is working. Now the case is to give the user the ability to select which fields they want to edit.

 

Example: Rather than editting Name, Address, City, State they can select Address, Comments, Status, Stage, etc.

 

Again, thanks for your help on this

tdeptdep

Another Question: Does the VF page have to be set to have a StandardController for the sObject you want to use with the fieldset?

 

I found this: http://forceguru.blogspot.com/2011/02/using-field-set-on-visual-force-page.html

 

I currently have 2 objects called within my controller so I cannot set it to be a StandardController, is it required?

 

"Error: Incorrect parameter for subscript. Expected Number, received Text" keeps getting generated when I try to apply the Repeat of Output Text on my result set.

 

Test Repeat:

<apex:repeat value="{!$ObjectType.TW_Project__c.FieldSets.Test}" var="f">
              <apex:outputText value="{!projresults[f]}" /> <br />
</apex:repeat>

Piece of Controller: 

  /* Establish Inputs for VF page */
   public string projaddress {get;set;}
   public string projcity {get;set;}
        
    /* Establish result lists & return */
    public list<TW_Project__c> projresults;
    public list<TW_Project__c> getProjResults() 
                        { return projresults; }
    
    
    /* Project search method */  
    public list<TW_Project__c> doProjSearch()
                    {
                        /* Make search variables dynamic by adding wildcard in front and back of input */
                        IF(projaddress != '') projaddress = '%' + projaddress + '%';
                        IF(projcity != '') projcity = projcity + '%';
                        
                        /* Initiate Multiple Query and Variable strings */
                        string projaddressonly;
                        string projcityonly;
                        string projboth;
                        string projvariables;

                        /* This is where the fields to query are set, works across all search queries */
                        projvariables =  'Id, Name, Street__c, City__c, State__c, Stage__c, Project_Type__c, Country__c';
                        
                        /* Set filter for searches */
                        projaddressonly = 'SELECT ' + projvariables + ' FROM TW_Project__c WHERE Street__c LIKE :projaddress LIMIT 100';
                         projcityonly = 'SELECT ' + projvariables + ' FROM TW_Project__c WHERE City__c LIKE :projcity LIMIT 100';
                         projboth = 'SELECT ' + projvariables + ' FROM TW_Project__c WHERE Street__c LIKE :projaddress AND City__c LIKE :projcity LIMIT 100';
                         
                         /* Determine which query to run */     
                         IF( projaddress != '' & projcity == '') //Provided Address, Blank City
                                {
                                projresults = Database.query(projaddressonly);
                                }
                       
                         ELSE IF( projcity != '' && projaddress == '') //Provided City, Blank Address
                                {
                                projresults = Database.query(projcityonly);
                                }
                                
                         ELSE //Both Address and City are populated
                                {
                                projresults = Database.query(projboth);
                                }     
                    
                   /*  Backup of Original Search Method                                   
                        projresults = [ SELECT Id, Name, Street__c, City__c FROM TW_Project__c WHERE Address__c LIKE :projaddress OR City__c LIKE :projcity LIMIT 100 ];
                  */                              
                                                   
                    return null;
                   }

 


Abhinav GuptaAbhinav Gupta

No you don't need a standard controller for use of fieldset. And for the error, you are trying to use dynamic binding with a list of records, it should be with one of them only i.e. projresults is a collection, you can never get a field value out of a collection, it should be single record

This code should work:

<apex:repeat value="{!projresults}" var="projRes">
  <apex:repeat value="{!$ObjectType.TW_Project__c.FieldSets.Test}" var="f">
              <apex:outputText value="{!projRes[f]}" /> <br />
  </apex:repeat>
</apex:repeat>

 

This was selected as the best answer
tdeptdep

ah, that makes sense but still isn't working - nothing shows up when compiled and ran. 

 

Above the area I am testing I have a datatable which returns the same dataset and that is working.

 

EDIT: I didn't have it wrapped in my update panel ^_^ Going to do some more testing and get back

tdeptdep

This works! 

Thanks for your help!

 

Now I am going to investigate giving the end user the ability to change the repeat FieldSet.xxxx value.

 

If you have any information on that it would be greatly appreciated :)

 

I am assuming I will have a Get/Set function within the controller which controls the string that will be pushed into the Inner Repeat Value. User would control with a drop down or radio button, something along those lines :)

tdeptdep

Just to follow up on this, I got it to work so if anyone needs in the future:

 

It is a drop-down list that controls which FieldSet is shown

 

<apex:pageBlock id="dynamic01">
<apex:form> <apex:selectList value="{!fieldSetselector}" size="1" onchange="changeDrop()"> <apex:selectOption itemValue="- None -" itemLabel="- None -"/> <apex:selectOption itemValue="Test1" itemLabel="Test1"/> <apex:selectOption itemValue="Test2" itemLabel="Test2"/> </apex:selectList> <br /> <!-- Output panel to wrap repeats --> <apex:outputPanel id="repeatlist"> <apex:repeat rendered="{!IF(fieldSetselector = 'Test1' , true, false)}" value="{!projresults}" var="projRes"><br /> <apex:repeat value="{!$ObjectType.TW_Project__c.FieldSets.Test}" var="f"> <apex:inputField value="{!projRes[f]}" /> </apex:repeat><br /> </apex:repeat> <apex:repeat rendered="{!IF(fieldSetselector = 'Test2' , true, false)}" value="{!projresults}" var="projRes"><br /> <apex:repeat value="{!$ObjectType.TW_Project__c.FieldSets.Test1}" var="f"> <apex:inputField value="{!projRes[f]}" /> </apex:repeat> </apex:repeat> </apex:outputPanel> </apex:form> </apex:pageBlock>

 

Abhinav GuptaAbhinav Gupta

I'm glad it worked :)