Monday, August 25, 2014

How to use an inline Visualforce page in Record Details Page?

How to use an inline Visualforce page in Record Details Page?

An inline visualforce page is a vf page which can be embedded within a detail page of a record. Salesforce allows doing so, in the edit page layout option. A vf page would be available for embedding in the detail page layout provided page is using standard controller of that particular object. For example, in the below example a inline vf page of standard controller 'contact' would be available for embedding in contact records only.

Visualforce Page:

<apex:page standardController="contact" extensions="InLineController">
 <apex:form >
   <apex:pageBlock title="My Inline Visualforce page">
    <b>Account Name : </b> <apex:outputField value="{!accRec.name}"/><br/>
    <b>Account Number: </b> <apex:outputField value="{!accRec.accountnumber}"/><br/>
     <b>Annual Revenue : </b>    <apex:outputField value="{!accRec.annualrevenue}"/>
   </apex:pageBlock>
 </apex:form>
</apex:page>

Controller:

public class InLineController {
 Public contact conRec{get;set;}
 Public id accRecId;
 Public account accRec{get;set;}
 public InLineController(ApexPages.StandardController controller) {    

   if(ApexPages.currentPage().getParameters().get('id') != null) {
   
     accRecId = [select id,accountid from contact where id = :ApexPages.currentPage().getParameters().get('id')].accountid;
      if(accRecId != null)
         accRec = [select id,name,accountnumber,annualrevenue from account where id =:accRecId];
         
   }
 }

}



once you complete the VF and Controller add the VF section in Contact Detail Page Layout.

save image


Output:

save image










0 comments:

Post a Comment

 
| ,