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
TC AdminTC Admin 

HELP - What's wrong with my save child item visual force page?

I have the below visual force page that displays a table of the time sheet itesm on a time sheet.
However if you try to press save i get " ERROR: There is no record to save"

Any ideas what i'm missing?

VisualForce page:
<apex:page standardController="Time_Sheet__c" extensions="TimeSheetEditAllItemsList"> <apex:form > <apex:pageBlock > <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!GetItemsList}" var="TSi"> <apex:column style="width:5%" value="{!TSi.D_Project__c}"/> <apex:column style="width:5%" value="{!TSi.D_Type__c}"/> <apex:column style="width:5%" value="{!TSi.D_Product_Manager__c}"/> <apex:column style="width:5%" headerValue="Monday"> <apex:inputField value="{!TSi.Day_Monday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Tuesday"> <apex:inputField value="{!TSi.Day_Tuesday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Wednesday"> <apex:inputField value="{!TSi.Day_Wednesday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Thursday"> <apex:inputField value="{!TSi.Day_Thursday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Friday"> <apex:inputField value="{!TSi.Day_Friday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Weekend"> <apex:inputField value="{!TSi.Day_Weekend__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>

Apex Class:
PUBLIC CLASS TimeSheetEditAllItemsList {
PUBLIC LIST <Time_sheet_items__c> GetItemsList {get;set;}
PUBLIC TimeSheetEditAllItemsList(ApexPages.StandardController ctrl){ 
 GetItemsList = [
        SELECT Id,Time_Sheet__c,D_Product_Manager__c,D_Type__c,D_Project__c,Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c,Day_Thursday__c,Day_Friday__c,Day_Weekend__c,Day_Monday_Comment__c,Day_Tuesday_Comment__c,Day_Wednesday_comment__c,Day_Thursday_Comment__c,Day_Friday_Comment__c,Day_Weekend_Comment__c 
        FROM Time_Sheet_Items__c 
        WHERE       Time_Sheet__c= : ctrl.getId() ORDER BY  id ASC
        ];
    }
}

ERROR:
Error upon save button
Best Answer chosen by TC Admin
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

You are using the standard controller Save method which works on the Time_Sheet__c record from which the request was originated and thus it is giving this error. Once you will click on save it will save controller record only, like getItem = (Time_Sheet__c) ctrl.getRecord();
Only the record from ctrl.getRecord() will be updated by the standard controller. 

You need to write a custom save method in your extension controller like this:
public pageReference save(){
        UPSERT GetItemsList ;
        return null;
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

You are using the standard controller Save method which works on the Time_Sheet__c record from which the request was originated and thus it is giving this error. Once you will click on save it will save controller record only, like getItem = (Time_Sheet__c) ctrl.getRecord();
Only the record from ctrl.getRecord() will be updated by the standard controller. 

You need to write a custom save method in your extension controller like this:
public pageReference save(){
        UPSERT GetItemsList ;
        return null;
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
TC AdminTC Admin
Thank you Khan Anas, This worked perfectly!