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
Deepak Techmodel5Deepak Techmodel5 

how to create 'save' button in vf for saving child record values once values entered? Need in declarative method as well as non- declarative method?

Best Answer chosen by Deepak Techmodel5
NagendraNagendra (Salesforce Developers) 
Hi Deepak,

You can add a controller extension to handle the save.

Create a new Apex class like this:
public class HRTaskAssignmentExtension
{
    private HR_Task_Assignment__c taskAssignment;
    List<HR_Task__c> tasks;

    public HRTaskAssignmentExtension(ApexPages.StandardController controller)
    {
        taskAssignment = (HR_Task_Assignment__c) controller.getRecord();
        // add all your necessary fields to the query below
        tasks = [select Id from HR_Task__c where HR_Task_Assignment__c = :taskAssignment.Id]; 
    }

    public List<HR_Task__c> getTasks()
    {
        return tasks;
    }

    public PageReference saveTasks()
    {
        update tasks;
    }
}
Add the extension to your Visualforce page:
<apex:page standardController="HR_Task_Assignment__c" extensions="HRTaskAssignmentExtension">
Use the new getTasks() method from the controller extension in your pageBlockTable.
<apex:pageBlockTable value="{!tasks}" var="task">
Finally, add the new saveTasks() method from the controller extension to your command button.
<apex:commandButton action="{!saveTasks}" Value="Save"/>
Tweak the sample code as per your requirement which will help you in achieving the above challenge.

Hope this helps.

Mark this as resolved if the information helps.

Thanks,
Nagendra