0

I have an apex:repeat with Child Name and Edit button displayed. (3 children in the list) ListMember

<apex:repeat value="{!listMember}" var="member">
     <label>Name</label>
     <apex:commandLink>Edit
         <apex:param name="fieldName" value="{!member.name}"/>
     </apex:commandLink>
</apex:repeat>

On click of Edit button I open the below inputField with Save button. ListM. The correct child is opened based on the rendering condition of FieldName that is being passed.

<apex:repeat value="{!listM}" var="child">  
      <apex:outputPanel rendered="{!($CurrentPage.parameters.fieldName == Child.name)}">
           <apex:form> 
                <apex:inputField value="{!child.Name}" id="childNewName"/>                                   
                   <apex:commandLink action="{!updateHFProfile}">
                     <apex:commandButton value="Save"/>
                     <apex:param name="pramvalue" assignTo="{!pramvalue}" value="memberRecords"/>                                            
                   </apex:commandLink>
            </apex:form>      
    </apex:outputPanel>
</apex:repeat>

ISSUE After editing the 'Child 1' name and clicking on SAVE, it is correctly updating the child name. But if I Update Child 2 or Child 3, the name is not being saved!! What could be the issue here?

Apex class

public String pramvalue{get;set{pramvalue=value;}}
public PageReference updateHFProfile(){
   update updatMembersList;
}

     public list<Member__c> updatMembersList{get;set;}
     public list<Member__c> listM{
        get{
            List<Member__c> listlocal;
            listlocal=[Select Id,NameFrom Member__c where Account_Name__c=: profileId__c];
            if(listlocal!=null && listlocal.size()>0){
                System.debug('members size--->'+listlocal.size());                
                updatMembersList = listlocal;
            }
    return listlocal;
        }
       set;
     }
0
1

You need to change your repeat to use updatMembersList:

<apex:repeat value="{!updatMembersList}" var="child">

You don't really need two separate List<Member> properties, though. The problem is, your getter for listM overwrites the results every call. The Lazy Load Pattern can fix this issue. Try replacing updatMembersList and listM with one list that looks like:

public List<Member__c> children
{
    get
    {
        if (children == null)
        {
            // INITIALIZATION LOGIC HERE
            // You only want to run it once
        }
        return children;
    }
    private set;
}
public PageReference updateHFProfile(){
   update children;
}
3
  • that didn't help – sfdcFanBoy May 19 '16 at 7:12
  • I knew No issue with controller, because the first record was saving anyways. Figured out the issue with VF. It is because of the extra <apex:form>. Thanks anyways for looking into this @Adrian Larson – sfdcFanBoy May 19 '16 at 8:53
  • 1
    @sfdcFanBoy fair enough. You still don't really need two lists though. – Adrian Larson May 19 '16 at 13:29
0

I have figured out the issue. It is because of <apex:form> inside the apex:repeat. It is treating as new form for every record. I put the <apex:form> outside of the <apex:repeat>

<apex:form>
<apex:repeat value="{!listM}" var="child">  
    <apex:outputPanel>
        <!--ETC -->
    </apex:outputPanel>
</apex:repeat>
</apex:form>

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.