2
<apex:pageBlockTable var="l"  value="{!list}"> 
    <apex:column headerValue="links">
       <apex:commandLink value="Save" action="{!savelink}">
    </apex:column>
    <apex:column headervalue="field">
     <apex:inputfield={!l.object.field__c}/>
   </apex:column>
<apex:pageBlockTable>

Controller

public id recordid; (it will have the record id which is being modified)
object obj{get;set;} 
public void savelink()
{
  obj = [Select id FROM obj WHERE id=recordid]
  update obj;
}

public class wrapper
{
  public object objwrap;
  public wrapper(objwrap)
  {
    this.objwrap = objwrap;
  }
}

The input field value is not being updated on field value change. Any help is much appreciated.

2 Answers 2

0

You're querying the object and then updating with that newly queried record, meaning you're not making any changes.

Really your input fields are bound to the object instance inside of the wrapper, so all you need to do is update that. If you're feeling lazy you could just update all of them:

public void savelink()
{
  List<SObject> objects = new List<SObject>();
  for(wrapper w : list)
  {
    objects.add(w.object);
  }

  update objects;
}

Or you could search the list:

public void savelink()
{
  for(wrapper w : list)
  {
    if (w.object.Id == recordId) update w.object;
  }
}

But ideally, when you populate the list you could populate a map at the same time, then simply do:

public void savelink()
{
    Wrapper w = wrapperMap.get(recordId);

    if(w != null) update w.object;
}

All that aside, I'm assuming you've simplified the wrapper for the sake of brevity here, but if not, then you don't really need it :)

1

Problem in your code is place where you are using SOQL.

public void savelink()
{
 obj = [Select id FROM obj WHERE id=recordid]
 update obj;
}

Whenever , button is clicked you are retrieving record from database which is overwriting anything it has then you are saving it back.

You should be using SOQL in constructor of controller instead of save method.

2
  • I'm actually passing the recordid as a parameter on click of other commandlink, so the recordid would be null in the constructor.
    – cartman
    May 7, 2015 at 4:09
  • If you are passing record Id and retrieving it from Database, When you are updating record ? There should be some statement between SOQL and DML May 7, 2015 at 4:20

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.