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
stollmeyerastollmeyera 

Having an individual UPDATE button next to each record on VF page

I have a VG page that shows all existing contacts on an Account, as well as allows you to add new contacts to the Account; it does so through a pageblockTable and some extensions.  I need a way to add an Update button next to each one of the lineitems on the pageblockTable to allow the user to make a change to one Contact and then quicksave it separate from the rest.  

 

Is this possible?

Best Answer chosen by Admin (Salesforce Developers) 
Andy BoettcherAndy Boettcher

You'd have a CommandButton or CommandLink in your row - and between the open/close tags of that CB or CL, you'd have <apex:param>.

 

<apex:param name="q" value="{!contact.Id}" assignTo="{!YourControllerVariable}" />

 

Then, in your controller, you'd have:

 

public class YourClass() {

// Getter
public String YourControllerVariable {get;set;}

// Method
public void saveMethod() {

(Your update code goes here, you can reference "YourControllerVariable" as the Id)

}

}

 

 

Let me know if that helps...

All Answers

stunaitestunaite

It is!

 

The update buttom shall be a commandbuttom with a parameter with the id contact value you want to update.

The controller will receive that parameter. Find in the list which is linked to the pageBlockTable the right contact. and then do the DML update instruction.

Don't need to rerender the pageBlockTable.

 

 

PS: If it solve yor problem mark it as "solution"

 

 

 

stollmeyerastollmeyera

Are you saying that I need to add a save method to my class?  If so, how do I reference the specific row that the user is on and have the save only apply to that row?

Andy BoettcherAndy Boettcher

Best way I'd do it is via a helper class in your PageBlockTable.  The CommandButton would invoke a custom method in your controller - you would pass through (or otherwise set) the helper class object when the CommandButton is pressed and your update logic would be fired.  Voila!

 

-Andy

raseshtcsraseshtcs

make use of apex param tag to send the id of the record for which the button  is clicked. Use the id in the controller to perform the update operation

Let me know if u need an example

stollmeyerastollmeyera

@rasechtcsIt makes sense how to use the param tag in the VF page, but I would greatly appreciate an example of how to incorporate that into the class.  

Andy BoettcherAndy Boettcher

You'd have a CommandButton or CommandLink in your row - and between the open/close tags of that CB or CL, you'd have <apex:param>.

 

<apex:param name="q" value="{!contact.Id}" assignTo="{!YourControllerVariable}" />

 

Then, in your controller, you'd have:

 

public class YourClass() {

// Getter
public String YourControllerVariable {get;set;}

// Method
public void saveMethod() {

(Your update code goes here, you can reference "YourControllerVariable" as the Id)

}

}

 

 

Let me know if that helps...

This was selected as the best answer