1

I have a custom object "Success__c" that I am attempting to create a visualforce page for. I would like to have the parent (MD relationship via account__c) Account fields on the page, as well as the sibling objects from the shared parent Account, Opportunities and Solutions__c. The problems I am having are as follows:

1. Although I have the health and successes related via a related list on the successes, the successes detail is nested and looping itself and i'm not sure what I did. (Plus I'd like this on the page not the related list.

My Page is Repeating the Detail Section

Here is how my page is setup: Updated 1:54 pm Monday

<apex:page standardController="Success__c" extensions="S_ControllerExtension" tabStyle="Success__c">
     <apex:detail relatedList="true">
          <apex:pageMessages />
     </apex:detail>
     <apex:form >
    <apex:pageblock id="CustomList" title="Related Solutions"  >
       <apex:pageBlockTable value="{!solutions}" var="solutions" rendered="{!NOT(ISNULL(solutions))}">
            <apex:column value="{!solutions.Name}"/>
            <apex:column value="{!solutions.Account__r.Name}"/>
            <apex:column value="{!solutions.Solutions_Status__c}"/>
           <apex:column value="{!solutions.Go_Live__c }"></apex:column>
       </apex:pageBlockTable>

Here is my extension:

    public class s_ControllerExtension
{
    public Success__c s {get;set;}
    public Account acc 
    {
        get
        {
         if( acc== null)
            {
                acc= 
                [SELECT id, name, type
                FROM Account
                WHERE id=:s.account__c];
             }
             return acc;
        }
        private set;
     }
    public List <Solutions__c> Solutions
    {
        get
        {
            if( Solutions == null)
            {
                Solutions = 
                [SELECT id, name, account__c, Go_Live__c, Solution_Status__c 
                FROM Solutions__c  
                WHERE account__c=:s.account__c];
             }
             return solutions;
        }
        private set;
     }
     public List<Opportunity> openoppty
     {
         get
         {
                if( openoppty== null)
                {
                 openoppty=
                  [SELECT id, name, Amount, AccountId, IsClosed
                   FROM Opportunity
                   WHERE IsClosed=TRUE and AccountId=:s.account__c];
              }
              return openoppty;
          }
          private set;
      }
     public List<Opportunity> closedWonoppty
     {
         get
         {
             if( closedWonoppty==null)
             {
                 closedWonoppty=
                  [SELECT id, name, Amount, AccountId,IsClosed,IsWon
                   FROM Opportunity
                   WHERE IsClosed=TRUE and IsWon=TRUE and AccountId=:s.account__c];
              }
              return closedWonoppty;
          }
          private set;
     }
     public List<Case> ticket
     {
         get
         {
             if( ticket==null)
             {
                 ticket=
                  [SELECT id, CaseNumber, Subject,AccountId,IsClosed, ContactId, Status,description,ClosedDate
                   FROM Case
                   WHERE AccountId=:s.account__c];
              }
              return ticket;
          }
          private set;
     }
           public List<Success__c> rS
     {
         get
         {
             if( rs==null)
             {
                 rS=
                  [SELECT id, S_Date__c, Account__c,Strengths__c,Weaknesses__c, Threats__c, AccountHealthStatus__c,Last_S_Review__c
                   FROM Success__c
                   WHERE account__c=: s.account__c ];
              }
              return rS;
          }
          private set;
     }
     public s_controllerExtension( ApexPages.StandardController sc ) 
     {
      s = (Success__c) sc.getRecord();
}
}

These are doing this: page view with the controller and vf page

BUT the preview looks fine... enter image description here If you aren't able to help directly if you could please point me in the right direction I would really appreciate it.

I have on hand: Visualforce Developers Guide Visualforce in Practice The visualforce cheatsheet google

Thank you so much in advance.

I found this question similar to mine, however i don't know where to add in the render... SObject row was retrieved via SOQL without querying the requested field: CustomLead__c.CompanyName__

  • I added <apex:inputhidden value="{!Success__c.account__c}" /> to my field and now I am still receiving the of the Success__c Detail section, however it is not nesting & duplicating itself, so that is an improvement. Now, however it no longer shows the related lists, which is a negative that I lost all related objects – MeighanRocksSF Dec 19 '14 at 16:00
  • Meighan -- note in my answer that I moved the apex:detail outside of the apex:form – cropredy Dec 22 '14 at 21:02
  • Sorry I have properly updated the page, it now shows the detail outside of form, which is how it was in my sandbox, sorry for the error on here. Still looping. – MeighanRocksSF Dec 22 '14 at 21:55
  • try taking the pageMessages out of the apex:detail tag - I've never seen that done before – cropredy Dec 22 '14 at 22:59
1

Here's the essence of the solution if I understand the issue wherein you want to display a single Success__c and its parent Account with sibling Opportunities and Healths.

Controller

public class SuccessController {

  public Account getAccount() {    
     if (this.a == null)
       this.a =  [select id, name,    // get success's Account & children
                  (select id, name from Opportunities),
                  (select id, name, go_live__c, status__c from Healths__r)
                 from Account where id = :s.account__c];
     return this.a; 
  }
  public Boolean getHasHealths() {
      return getAccount().healths__r.size() > 0;
  }
  private Account a;
  private Success__c  s;  
  public SuccessController (ApexPages.StandardController ctlr) {
    ctlr.addFields(new List<String> {'account__c'});  // ensure getRecord() fetches other success fields not explicitly referenced on page
    this.s = (Success__c) ctlr.getRecord();
 }
}

VF page

<apex:page standardController="Success__c" extensions="SuccessController">
 <apex:pageMessages />
 <apex:detail relatedList="true"></apex:detail>

 <apex:form >
 <!-- Here is where we display the siblings -->
 <apex:pageblock id="CustomList" title="Related Health"  >
   <apex:pageBlockTable value="{!account.healths__r}" var="ahc"> rendered="{!hasHealths}"/>
        <apex:column value="{!ahc.Name}"/>
        <apex:column value="{!account.name}"/>
        <apex:column value="{!ahc.Status__c}"/>
       <apex:column value="{!ahc.Go_Live__c }"/>
   </apex:pageBlockTable>
   <apex:outputLabel value="No records to display" rendered="{!(NOT(hasHealths)}" styleClass="noRowsHeader"></apex:outputLabel>

  <!-- add another pageBlockTable for the Opportunities -->
 </apex:pageblock>
</apex:form>
</apex:page>

Note - I typed this in and there may be typos

  • This just gives me the Success__c Page detail, and not the related account record (Parent) or health object records (Child B) – MeighanRocksSF Dec 19 '14 at 16:36
  • Thank you for identifying the error in the OP; the standard controller getRecord() only returns fields in Success__c that are referenced on the page. Hence success__c.account__c isn't included, my error. I fixed the controller above – cropredy Dec 19 '14 at 19:17
  • Adding the account__c has me looping in nested screens of details again – MeighanRocksSF Dec 19 '14 at 21:01
  • When I use development mode and preview my page, the success and health section showup – MeighanRocksSF Dec 19 '14 at 21:32
  • MeighanRocksSF - I am sorry you are having these difficulties -- please edit OP and just insert the state of your code as it is now (remove all the old stuff) and include screen shot of incorrect behavior. I also changed the VF page to move the detail component outside of the form component to mirror an example I have in my own org that works fine – cropredy Dec 20 '14 at 1:21
1

THANK YOU TWITTER:

The answer here thanks to @bigassforce is...

DETIAL, it needs to be removed from the page or the browser will slow as it endlessly loops, and the world will come to an end.

<apex:form >
     <apex:inputhidden value="{!Conditions_of_Success__c.Account__c}" />

 REMOVE THIS ----><apex:detail relatedList="true"></apex:detail><---It's got to GO, got to go!

 <apex:pageblock title="Related Solutions"  >
 <apex:pageBlockSection title="All Solutions">
   <apex:pageBlockTable value="{!account.Solutions__r}" var="sol">
        <apex:column value="{!sol.Name}"/>
        <apex:column value="{!account.name}"/>
        <apex:column value="{!sol.Solution_Status__c}"/>
       <apex:column value="{!sol.Go_Live__c }"/>
   </apex:pageBlockTable>
</apex:pageBlockSection>

  <apex:pageblock title="Related Opportunities"  >
   <apex:pageBlockSection title="All Opportunities">
   <apex:pageBlockTable value="{!account.Opportunities}" var="opp"> 
        <apex:column value="{!opp.Name}"/>
        <apex:column value="{!account.name}"/>
        <apex:column value="{!opp.StageName}"/>
       <apex:column value="{!opp.Revenue_Type__c}"/>
   </apex:pageBlockTable>
   </apex:pageBlockSection>
 </apex:pageblock>
  </apex:pageblock>
</apex:form>
</apex:page>

and... tada! The page works, you can see the page detail and related lists from the account object no problem, no loop

0

Here is an example :

"TotalNumberofQuestions" is Map of <Master,Detail>, Detail can be single record or list of records. If it is list records you can use another table or repeat block. Let me know if it helps. (SQS acts as key and renders 'Value', also it acts as variable)

<apex:pageblockTable value="{!TotalNumberofQuestions}" var="SQS"> 

<apex:column value="{!SQS}" headerValue="Question set"/>
<apex:column value="{!TotalNumberofQuestions[SQS]}" headerValue="Total number of Questions"/>
<apex:column value="{!Notreviewed[SQS]}" headerValue="Outstanding Peer Review"/>
<apex:column value="{!TotalAgreed[SQS]}" headerValue="Peer Review Outcome - Agreed"/>
<apex:column value="{!TotalDisAgreed[SQS]}" headerValue="Peer Review Outcome - Disagreed"/>
<apex:column value="{!TotalNA[SQS]}" headerValue="Peer Review Outcome - N/A"/>

</apex:pageblockTable>
  • sadly I don't follow your table and how I am connecting Child A to Parent to Child B. Which is the parent in your description, which is Child A and which is Child B? – MeighanRocksSF Dec 19 '14 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.