January 9, 2015

apex:detail in Apex in Salesforce

Sample Code:

Visualforce page:

  1. <apex:page controller="Sample">  
  2.   
  3.     <apex:form >  
  4.   
  5.         <h1>Below is the Account detail</h1>  
  6.         <apex:detail subject="{!AccountId}" relatedList="false"/>  
  7.   
  8.     </apex:form>  
  9.   
  10. </apex:page>  

Apex Controller:

  1. public class Sample {  
  2.   
  3.     public Id AccountId {get;set;}  
  4.   
  5.     public Sample() {  
  6.   
  7.         AccountId = '0019000001BoVNx';  
  8.   
  9.     }  
  10.   
  11. }  

Output:



4 comments:

  1. One Question:
    When we use this tag, it is showing all the available Account fields.

    But if I want to display only specific fields like Account Name, Phone, Fax and website on the page, then how we can achieve this.

    ReplyDelete
    Replies
    1. Use apex:outputField. You can find an example - http://www.infallibletechie.com/2015/04/what-is-difference-between-outputfield.html

      Delete
  2. It is showing that
    content is not allowed in trailing section

    ReplyDelete
    Replies
    1. If you are trying to show XML content, check the content of the XML. Make sure the content is correct.

      Delete