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
acrozieracrozier 

Creating a custom edit page

I have two Objects with a Master-Detail relationship.  I have created a custom edit page for the child object but the page only displays the line item that you click edit for and not the other child objects related to the parent.  How can I create an SOQL statement to pull in all child objects related to parent to be edited.  Code is below.

 

Parent= Job__c

Child= AIIncentive__c

 

 

VisualForce page (Second DataTable is only there to test SOQL statements)

<apex:page standardController="AIIncentive__c" extensions="Incent">
    <apex:form >
     <apex:pageBlock >
       
       <apex:pageBlockTable value="{!AIIncentive__c}" var="incent">
         <apex:column headerValue="QTY">
           <apex:inputField value="{!incent.QTY__c}"/>
         </apex:column>
         <apex:column headerValue="Description">
           <apex:inputField value="{!incent.Description__c}"/>
         </apex:column>
         <apex:column headerValue="Honoraria__c">
             <apex:inputField value="{!incent.Honoraria__c}"/>
         </apex:column>
         <apex:column headerValue="Job #">
             <apex:outputField Value="{!incent.Job__c}"/>
         </apex:column>
       </apex:PageBlockTable>
       <apex:PageBlockTable value="{!Incents}" var="I">
           <apex:column >
           <apex:OutputField value="{!I.QTY__c}"/>
           </apex:column>
       </apex:PageBlockTable>
       <apex:commandButton value="Save" action="{!save}"/>     
     </apex:pageBlock>
   </apex:form>
 
</apex:page>

 Extension

public with sharing class Incent {
public list<AIIncentive__c> Incents {get; set;}
public list<job__c> job {get; set;}
public id jobid;
public string r {get; set;}
    public Incent(ApexPages.StandardController controller) {
     jobid = apexpages.currentpage().getParameters().get('id');
        r = [Select Name, id FROM Job__c WHERE id = :jobid limit 1];
        Incents = [Select QTY__c, Description__c,  Honoraria__c, Job__c  From AIIncentive__c  where Job__c = :r];     
        }
      }
      

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I think your object types are a little confused.  You are using a standard controller of AIIncentive__c, but then treating the id as a job in your extension controller.

 

I think it should be more like:

 

 

  public Incent(ApexPages.StandardController controller) {
     id icentId= apexpages.currentpage().getParameters().get('id');
     jobid=[select id, Job__c from AllIncentive__c where id=:incentId].Job__c;
        r = [Select Name, id FROM Job__c WHERE id = :jobid limit 1];
        Incents = [Select QTY__c, Description__c,  Honoraria__c, Job__c  From AIIncentive__c  where Job__c = :jobid];     
        }
      }

 

All Answers

bob_buzzardbob_buzzard

I think your object types are a little confused.  You are using a standard controller of AIIncentive__c, but then treating the id as a job in your extension controller.

 

I think it should be more like:

 

 

  public Incent(ApexPages.StandardController controller) {
     id icentId= apexpages.currentpage().getParameters().get('id');
     jobid=[select id, Job__c from AllIncentive__c where id=:incentId].Job__c;
        r = [Select Name, id FROM Job__c WHERE id = :jobid limit 1];
        Incents = [Select QTY__c, Description__c,  Honoraria__c, Job__c  From AIIncentive__c  where Job__c = :jobid];     
        }
      }

 

This was selected as the best answer
acrozieracrozier

I could kiss you.

acrozieracrozier

Is there a function to call to Save and add new for the aforementioned Visualforce page?

bob_buzzardbob_buzzard

You'll have to code those up yourself.  There is a save on the standard controller, but that will only save the record that you clicked on to get to this page (i.e. the record id in the URL).

 

Do you just want to add another row, or do you want to be able to remove existing rows etc?  

 

Here's a blog post I wrote a while ago that should give you some pointers, although its not a direct match for what you are trying to do:

 

http://bobbuzzard.blogspot.com/2011/07/managing-list-of-new-records-in.html