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 

Apex coding to pass VisualForce Page parametrs

Hi all,

I'm trying to write a related list button on a master record that opens a table that you can edit certain fields of the masters child records.

My visual force page works but gets ALL child records in the system not just those relating to the master record I am on.

My Apex coding is:

public class EditAllButtonForTimeSheetController
{
    //This will store the Id from the URL i.e., the Id of the Record that belongs to the Master Object
    public String TSRecordId        {get; set;}
    public List<Time_Sheet_Items__c> TSiRecords  {get; set;}
    public Time_Sheet__c TSRecord                 {get; set;}
    //Constructor. This would build everything for our VF Page.
    public EditAllButtonForTimeSheetController()
    {
        TSRecordId = ApexPages.CurrentPage().getparameters().get('id');

        //Make sure we have the Id in the URL
        if(!String.isBlank(TSRecordId)){

            //Fetch the Time Sheet Record Details
            TSRecord =
            [SELECT ID,Name,Time_Sheet_Week_Ending__c FROM Time_Sheet__c WHERE Id = :TSRecordId ];

            //Fetch all the Time_Sheet_Items Records with respect to the Time_sheet Record. 
        //Note: Child_To_Parent_Lookup__c  is Lookup/M-D field on my Child SObject to the Parent – Master
            TSiRecords =
                [SELECT Id,Time_Sheet__c,D_Type__c,D_Product_manager__c,D_Project__c,
        Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c,Day_Thursday__c,Day_Friday__c,Day_Weekend__c
                FROM TIme_Sheet_Items__c WHERE Time_sheet_ID__c = :TSRecordId ];
                
        }
    }
}


VF PAGE

<apex:page standardController="Time_Sheet_Items__c"
              Extensions="EditAllButtonForTimeSheetController">
  <apex:form >
    <apex:pageBlock >
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save"
                            action="{!save}"/>
      </apex:pageBlockButtons>
      <apex:pageBlockTable value="{!Time_Sheet_Items__c}"
                           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>

Any help would be great.
Abhishek_DEOAbhishek_DEO
Could you replace follwoing "<apex:pageBlockTable value="{!Time_Sheet_Items__c}" var="TSi">" with "<apex:pageBlockTable value="{!TSiRecords}" var="TSi">" and see if it is working?
TC AdminTC Admin
HI, I have alredy tried this before with no success. I still get this eror message:

Id value a0R7E0000003ckd is not valid for the Time_Sheet_Items__c standard controller 

The ID value is for the master record. It like its trying to use my master record ID as the Ids for the child records tables but I do not know why.
Abhishek_DEOAbhishek_DEO

Did you get this error after the change I suggested? Since, you are using "Time_Sheet_Items__c" as standard controller, value in "id" parameter(in URL) should be a valid recordId of "Time_Sheet_Items__c". Error is suggesting the same.

If you are passing child record id then use child object as standard controller.

Abhishek_DEOAbhishek_DEO
I think standard controller should be "Time_Sheet__c" . could you please check and see if it is working
TC AdminTC Admin
We are trying to apss the child Ids to the cisual force page. I need the statnard controller to be time_sheet_items_-c.

I was gettignt eh error before your change.  However if I remove the extention the visual force page runs but with ALL child records on the system not just the ones that are attached to the master. So I know the page works its is the apex that does not.