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
Jonathan Meltzer 14Jonathan Meltzer 14 

Using a subject-style parameter without using apex:detail?

I think there is something I am just not understanding...something basic.  I have written an extension to the Account controller, and have defined an account ID in that extension.  The account ID is defined as the account associated with the contact that is associated with the current user (this is for Communities).

When I use <apex:detail>, I can use subject={!AccountId} and the page is rendered with the correct record.  However, I do not want to use apex:detail, because I want more granular control over the fields that are being shown.  I cannot find a way to bring in the AccountId value when loading the page without using apex:detail, though.  The pageBlockTable works fine, but is there a way to bring a value into a pageBlock or pageBlockSection without using a pageBlockTable?

Current page:
 
<apex:page standardController="Account" extensions="AccountTab_CX">
    <apex:detail subject="{!AccountId}" relatedList="false" />
    <apex:pageBlock title="Support Contacts">
        <apex:pageBlockTable value="{!supportContacts}" var="s">
            <apex:column value="{!s.Contact_Name__c}"/>
            <apex:column value="{!s.Support_Contact__c}"/>
            <apex:column value="{!s.Email}"/>
            <apex:column value="{!s.Phone}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Current Extension code:
 
public with sharing class AccountTab_CX {

    private List<Contact> supportContacts;
    private Account acct;

    public AccountTab_CX(ApexPages.StandardController controller) {
        this.acct = (Account)controller.getRecord();
    }
    
    public Id getAccountId() {
        User u = [SELECT Id, Contact.AccountId, Contact.Account.Name FROM User WHERE Id = :UserInfo.getUserId()];
        return u.Contact.AccountId; 
    }
    
    public List<Contact> getSupportContacts() {
        List<Contact> supContacts = new List<Contact>();
        User u = [SELECT Id, Contact.AccountId, Contact.Account.Name FROM User WHERE Id = :UserInfo.getUserId()];
        if (u.Contact.AccountId <> NULL) {
            supContacts = [SELECT Contact_Name__c,Support_Contact__c,Email,Phone from Contact where AccountId = :u.Contact.AccountId and Support_Contact__c = TRUE ORDER BY Contact_Name__c];
        }
        return supContacts;
    }

}

New page, which does not bring in any record because I cannot find a way to define the subject.  The supportContacts are listed correctly, because the value of the pageBlockTable still gets defined correctly:
 
<apex:page standardController="Account" extensions="AccountTab_CX">
    <apex:form >
        <apex:pageBlock title="Account Details">
          <apex:pageBlockSection columns="1">
            <apex:outputField value="{!Account.Legal_Account_Name__c}"/>
            <apex:outputField value="{!Account.Support_Hrs_Allotted_Text__c}"/>
            <apex:outputField value="{!Account.Support_Hours_Used__c}"/>
            <apex:outputField value="{!Account.Support_Hrs_Pct_Used_Text__c}"/>
          </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock title="Environment">
          <apex:pageBlockSection columns="1">
            <apex:outputField value="{!Account.Client_OS__c}"/>
            <apex:outputField value="{!Account.MTier_OS__c}"/>
            <apex:outputField value="{!Account.CR_DBMS__c}"/>
            <apex:outputField value="{!Account.CR_DBMS_OS__c}"/>
            <apex:outputField value="{!Account.DBMS_Version__c}"/>
          </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock title="Account Team">
          <apex:pageBlockSection columns="1">
            <apex:outputField value="{!Account.Strategic_Account_Director_Text__c}"/>
            <apex:outputField value="{!Account.Relationship_Mgr_Primary__c}"/>
          </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock title="Support Contacts">
            <apex:pageBlockTable value="{!supportContacts}" var="s">
                <apex:column value="{!s.Contact_Name__c}"/>
                <apex:column value="{!s.Support_Contact__c}"/>
                <apex:column value="{!s.Email}"/>
                <apex:column value="{!s.Phone}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>