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
Chamil MadusankaChamil Madusanka 

Problems in <apex:detail>

I have few problems on <apex:detail>.

 

  1. Can we use <apex:detail> for custom Objects?
  2. When I use <apex:detail>, do I need to create any kind of page?

Plz anyone clarify about <apex:detail> .

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I've created an example page and controller in my dev org that are working as you desire:

 

Page:

 

 

<apex:page controller="DetailTestController">
 <apex:form >
  <apex:pageblock title="Accounts">
     <apex:pageBlockTable value="{!accounts}" var="account">
        <apex:column headerValue="Click">
           <apex:commandLink value="{!account.Name}" rerender="detail">
              <apex:param name="chosenId" value="{!account.id}" assignTo="{!chosenId}"/>
           </apex:commandLink>
        </apex:column>
     </apex:pageBlockTable>
  </apex:pageblock>
  <apex:outputPanel id="detail">
     <apex:detail subject="{!chosenId}"/>
  </apex:outputPanel>
 </apex:form>
</apex:page>

 

 

Controller:

 

 

public class DetailTestController {

   public Id chosenId {get; set;}
   
   public List<Account> getAccounts()
   {
   	   return [select id, Name from Account limit 10];
   }
}

 

 

 

All Answers

bob_buzzardbob_buzzard

The <apex:detail> component will work for any object, standard or custom.

 

You'll either need to embed this component in a page that has an id parameter, or set the subject attribute to the id of the object that you want to display the detail for.

Chamil MadusankaChamil Madusanka

In my case, I'm displaying the some applicantID in pageBlockTable. When we click one applicantID, I want to display that particular Applicant in detail page.

 

Here the code.

 

/*Visual page*/

 

 

<apex:page standardController="Applicant__c" extensions="view">

<script type="text/javascript">
      function getSelectedID(id) {      
          
          viewFunction(document.getElementById(id).value);
          
      }
      </script> 
  <apex:form >
  
  <apex:actionFunction name="viewFunction" id="vfunc" action="{!getApplicantByStatus}" rerender="view">
      <apex:param name="para" value=""/>   
  
    </apex:actionFunction>
  
      <apex:pageBlock title="Hello {!$User.FirstName}!">
          <apex:outputLabel value="Status :" for="status"/>
          <apex:inputField id="status" value="{!Applicant__c.Status__c}" onchange="getSelectedID('{!$Component.status}');">
                            
          </apex:inputField>
      </apex:pageBlock>
      
       <apex:pageBlock >
           <apex:panelgroup id="view">
              <apex:pageBlockTable id="viewApplicant" value="{!applicantNameByStatus}" var="app">
              
                  <apex:column headerValue="Applicant ID">
                  <apex:commandLink reRender="detail" value="{!app}">                  
                  <apex:param id="cid" value="{!app}"/>
                         </apex:commandLink>                        
                  </apex:column>
                 
                 
              </apex:pageBlockTable>
           </apex:panelgroup>
      </apex:pageBlock> 
      
  
 
</apex:form>
<apex:outputPanel id="detail">
<apex:actionStatus startText="Requesting...">
<apex:facet name="stop">

<apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false"  title="false"/>
</apex:facet>
</apex:actionStatus>
</apex:outputPanel>

</apex:page>

 

 

/*Controller*/

 

 

public class view {

    public view(ApexPages.StandardController controller) {

    }


    public Applicant__c applicant;
    public List<Applicant__c> applicantByStatusList {get;set;}
    private ApexPages.StandardSetController controller;
   
    public List<String> applicantNameByStatus{
        get;
        set;
        
        }
    
    
    
    
     
    public view(ApexPages.StandardSetController controller) {
        this.applicant=(Applicant__c)controller.getRecord();
        //this.controller = controller;
    }
    

    
     public PageReference getApplicantByStatus(){
     
    String para1=Apexpages.currentPage().getParameters().get('para');
        
         applicantByStatusList =new List<Applicant__c>();
         applicantNameByStatus=new List<String>();
         System.Debug('PARAMETER :: '+para1);
         applicantByStatusList =[SELECT Name,Name__c,Status__c,Interview_Date_Time__c FROM Applicant__c WHERE Status__c =:para1];
         
        
         for(Applicant__c a:applicantByStatusList){
            String name=(String)a.Name;
            
              applicantNameByStatus.add(name);
               
            }
          
         
         return null;
    }
}

 

no any error but not displaying the detail page

 

bob_buzzardbob_buzzard

This seems like a slightly about face way of doing this.

 

I'd suggest you'd be better to make the subject come from the controller rather than trying to scrape it from an apex param on the URL.  In my experience the server side redirects associated with page refreshes tend to lose the URL parameters.

 

Try the following:

 

 

<apex:page standardController="Applicant__c" extensions="view">

<script type="text/javascript">
      function getSelectedID(id) {      
          
          viewFunction(document.getElementById(id).value);
          
      }
      </script> 
  <apex:form >
  
  <apex:actionFunction name="viewFunction" id="vfunc" action="{!getApplicantByStatus}" rerender="view">
      <apex:param name="para" value=""/>   
  
    </apex:actionFunction>
  
      <apex:pageBlock title="Hello {!$User.FirstName}!">
          <apex:outputLabel value="Status :" for="status"/>
          <apex:inputField id="status" value="{!Applicant__c.Status__c}" onchange="getSelectedID('{!$Component.status}');">
                            
          </apex:inputField>
      </apex:pageBlock>
      
       <apex:pageBlock >
           <apex:panelgroup id="view">
              <apex:pageBlockTable id="viewApplicant" value="{!applicantNameByStatus}" var="app">
              
                  <apex:column headerValue="Applicant ID">
                  <apex:commandLink reRender="detail" value="{!app}">                  
                  <apex:param id="cid" value="{!app.id}" assignTo="{!chosenAppId}"/>
                         </apex:commandLink>                        
                  </apex:column>
                 
                 
              </apex:pageBlockTable>
           </apex:panelgroup>
      </apex:pageBlock> 
      
  
 
</apex:form>
<apex:outputPanel id="detail">
<apex:actionStatus startText="Requesting...">
<apex:facet name="stop">

<apex:detail subject="{!chosenAppId}" relatedList="false"  title="false"/>
</apex:facet>
</apex:actionStatus>
</apex:outputPanel>

</apex:page>

 

 

Controller:

 

 

public class view {

    public Id chosenAppId {get; set;}

    public view(ApexPages.StandardController controller) {

    }


    public Applicant__c applicant;
    public List<Applicant__c> applicantByStatusList {get;set;}
    private ApexPages.StandardSetController controller;
   
    public List<String> applicantNameByStatus{
        get;
        set;
        
        }
    
    
    
    
     
    public view(ApexPages.StandardSetController controller) {
        this.applicant=(Applicant__c)controller.getRecord();
        //this.controller = controller;
    }
    

    
     public PageReference getApplicantByStatus(){
     
    String para1=Apexpages.currentPage().getParameters().get('para');
        
         applicantByStatusList =new List<Applicant__c>();
         applicantNameByStatus=new List<String>();
         System.Debug('PARAMETER :: '+para1);
         applicantByStatusList =[SELECT Name,Name__c,Status__c,Interview_Date_Time__c FROM Applicant__c WHERE Status__c =:para1];
         
        
         for(Applicant__c a:applicantByStatusList){
            String name=(String)a.Name;
            
              applicantNameByStatus.add(name);
               
            }
          
         
         return null;
    }
}

 

 

Chamil MadusankaChamil Madusanka

I did the changes as your post. But I'm still getting the same result. That means no result.

kiranmutturukiranmutturu

use name attribute in the param tag apart from id....like 

<apex:param name="cid" value="{!app}"/>
bob_buzzardbob_buzzard

I've created an example page and controller in my dev org that are working as you desire:

 

Page:

 

 

<apex:page controller="DetailTestController">
 <apex:form >
  <apex:pageblock title="Accounts">
     <apex:pageBlockTable value="{!accounts}" var="account">
        <apex:column headerValue="Click">
           <apex:commandLink value="{!account.Name}" rerender="detail">
              <apex:param name="chosenId" value="{!account.id}" assignTo="{!chosenId}"/>
           </apex:commandLink>
        </apex:column>
     </apex:pageBlockTable>
  </apex:pageblock>
  <apex:outputPanel id="detail">
     <apex:detail subject="{!chosenId}"/>
  </apex:outputPanel>
 </apex:form>
</apex:page>

 

 

Controller:

 

 

public class DetailTestController {

   public Id chosenId {get; set;}
   
   public List<Account> getAccounts()
   {
   	   return [select id, Name from Account limit 10];
   }
}

 

 

 

This was selected as the best answer
ajaybharathajaybharath

Hi Bob

 

Can you please help me on this

 

This is my requirement , I also have the same problem with Component.Apex.Detail .. My requirement is to display the records of Account Object as Tabs Separately and each tab should contain its Detail and its Corresponding Related list

I have implemented the tab panel and corresponding tabs , but i'm not getting the Detail Component running dynamically
it shows no error too
This is my code

 

public with sharing class Trail {
     
    public List<Account> topAccounts;
    //public Id selectedId {get;set;}
 
    public Trail (){
        topAccounts = [SELECT Id,Name,AccountNumber,Site,
                AccountSource,AnnualRevenue,
                Industry,Phone,Type,Company_Name__c FROM 
                            Account LIMIT 10]; 

    }
    
    /*public List<Account> getAccount() {
                return [select id, Name from Account limit 10];
                      
    }*/
 
    public Component.Apex.TabPanel getTabbedView(){
        Component.Apex.TabPanel panel = new Component.Apex.TabPanel(
                                                       switchType = 'client',
                                                       title = 'Top 10 Accounts');
 
        String lastAcctId;
 
        for (Integer i = 0; i< topAccounts.size(); i++){
            Account o = topAccounts[i];
 
            if (lastAcctId != o.Id){
                Component.Apex.Tab acctTab = new Component.Apex.Tab();
                acctTab.label = o.Name;
                Component.Apex.Detail det = new Component.Apex.Detail();
                det.expressions.subject =  '{!topAccounts[i].Id}';
                det.relatedList = true;
                det.title = true;
                acctTab.childComponents.add(det);
                panel.childComponents.add(acctTab);
            }    
 
            lastAcctId = o.Id;
        }
        return panel;
    }
}

 VF Page

<apex:page controller="Trail">
    <apex:sectionHeader title="Top 10 Accounts"/> 
    <apex:dynamicComponent componentValue="{!tabbedView}"/><br/><br/>
</apex:page>

 

ajaybharathajaybharath

 

Hi All

 

This is it ! This code is working fine , to display accounts as tab along with its details and related lists
Vf page is the same

 

trail class:

 

public with sharing class Trail {
     
    public List<Account> topAccounts;
    public String tabbedView { set; }
    //public Id selectedId {get;set;}
 
    public Trail (){
        topAccounts = [SELECT Id,Name,AccountNumber,Site,
                AccountSource,AnnualRevenue,
                Industry,Phone,Type,Company_Name__c FROM 
                            Account LIMIT 10]; 

    }
    
    public Component.Apex.TabPanel getTabbedView(){
        Component.Apex.TabPanel panel = new Component.Apex.TabPanel(
                                                       switchType = 'client',
                                                       title = 'Top 10 Accounts');
 
        String lastAccountId;
 
        for (Integer i = 0; i< topAccounts.size(); i++){
            Account o = topAccounts[i];
 
            if (lastAccountId != o.Id){
                Component.Apex.Tab acctTab = new Component.Apex.Tab();
                acctTab.label = o.Name;
                Component.Apex.detail rl = new Component.Apex.detail();
                system.debug('Before *******');
                rl.subject=o.Id;
                rl.inlineEdit = true;
                rl.relatedList = true;
                rl.title = false;
                acctTab.childcomponents.add(rl);
                system.debug('After ******');
                panel.childComponents.add(acctTab);
            }    
 
            lastAccountId = o.Id;
        }
        return panel;
    }
}

 Thanks

 Aj

Eric WhippleEric Whipple

Bob,

 

It's good to have people like You, Jeff Douglas, and Jim Rae who just know everything.  Much easier than looking through the help docs!  Thanks!