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
Dorian - JLCDorian - JLC 

Related List Save Button on a Account in a Visualforce Page

Hi,

 

I'm building a VF Page that will be in a account. In this VF page I'm calling a related list :

 

<apex:dataTable value="{! account.agence__r}" var="item" border="2px;">
     
       <apex:column headerValue="Agence" style="padding: 2px 2px 2px 2px ;width:140px;">
          <apex:outputField value="{! item.name}" />
       </apex:column>
       
       <apex:column headerValue="Responsable" style="padding: 2px 2px 2px 2px ;width:140px;">
          <apex:outputField value="{! item.Z_responsable__c}" />
       </apex:column>
       
       <apex:column headerValue="Adresse" style="padding: 2px 2px 2px 2px ;width:140px;">
          <apex:outputField value="{! item.Z_adresse__c}" />
       </apex:column>
       
       <apex:column headerValue="Ville" style="padding: 2px 2px 2px 2px ;width:140px;">
          <apex:outputField value="{! item.Z_ville__c}" />
       </apex:column>
       
     </apex:dataTable>

 When the user click on " Modify " button (Custom Button not the SF Button ) all output become input, so the user can modify data (JavaScript function).

 

So to save changes I have to make a save button with an extension controller of Account, but I don't know how i can link the controller with the visualforce, I mean how can I get data when the user click on the button " Save " ?

 

I should do something like that but theses methode can be use for other object than standard Object ?

public class MyController {

    private final Account account;

    public MyController() {
        account = [SELECT Id, Name, Site FROM Account 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Account getAccount() {
        return account;
    }

    public PageReference save() {
        update account;
        return null;
    }
}

I know that I can acces to the data of an input like that :

data = account.InputName 

 But with the related List if I have Multiples records I can't do it , or i will have a tab with data of a specifique field of all related records ?

 

Best regards,

Dorian