How to Pass Record Id into Visualforce page to display the record of current Account calling extension method of apex class in Visualforce Salesforce | How to display related record of Account based on record Id in a Visualforce page using extension method of apex class in Salesforce Visualforce | Render as pdf in vf page

2,747 views

Hey guys, today in this post we are going to learn about How to Pass Record Id into Visualforce page to display the record of current Account calling extension method of apex class in visualforce Salesforce.

Visualforce includes nearly 150 built-in components that you can use on your pages. Components are rendered into HTML, CSS, and JavaScript when a page is requested. Coarse-grained components provide a significant amount of functionality in a single component, and might add a lot of information and user interface to the page it’s used on. Fine-grained components provide more focused functionality, and enable you to design the page to look and behave the way you want. To get more details about Display Records, Fields, and Tables in Visualforce, Click Here.

 

Final Output →

pass record id to display record in visualforce -- w3web.net

 

You can download file directly from github by Click Here.

 

Other related post that would you like to learn in Salesforce

 

  • Find the below steps â–¾

 

 

Step 1:- Create Visualforce Page : SalesAccountOrderFormPDFvFP.vfp

From Developer Console >> File >> New >> Visualforce Page

SalesAccountOrderFormPDFvFP.vfp [Component Visualforce Page]

  1.   <apex:page applyHtmlTag="false" showHeader="false" standardController="Account" extensions="SalesAccountOrderForm_Controller" renderAs="pdf" standardStylesheets="false"
  2.            applyBodyTag="false">
  3.     <head>
  4.         <style>
  5.             @page {
  6.             size: A4 portrait;
  7.             margin: 3mm;
  8.             }
  9.  
  10.             body {
  11.             font-family: sans-serif;
  12.             font-size: 11pt;
  13.             }
  14.             th {
  15.             min-height: 15px;
  16.             max-height: auto;
  17.             background:#ddd;
  18.             }
  19.             td {
  20.             min-height: 15px;
  21.             max-height: auto;
  22.             }
  23.         </style>
  24.     </head>
  25.     <body>
  26.         <table border="1" cellspacing="0" cellpadding="10" style="width: 100%; border-collapse: collapse; border-color: #000; text-align:left;">
  27.             <thead>
  28.                 <tr> 
  29.                     <th>Name</th>
  30.                     <th>Phone</th>
  31.                     <th>Industry</th>
  32.                     <th>Rating</th>
  33.                     <th>Description</th>
  34.                     <th>Website</th>
  35.                 </tr>     
  36.             </thead>
  37.  
  38.             <apex:repeat value="{!accObj}" var="accItem">                
  39.                 <tr width="100%" style="text-align: center;">
  40.                     <td style="text-align:left;"><apex:outputText value="{!accItem.Name}"/></td>
  41.                     <td style="text-align:left;"><apex:outputText value="{!accItem.Phone}"/></td>
  42.                     <td style="text-align:left;"><apex:outputText value="{!accItem.Industry}"/></td>
  43.                     <td style="text-align:left;"><apex:outputText value="{!accItem.Rating}"/></td>
  44.                     <td style="text-align:left;"><apex:outputText value="{!accItem.Description}"/></td>
  45.                     <td style="text-align:left;"><apex:outputText value="{!accItem.Website}"/></td>
  46.                 </tr>  
  47.  
  48.                 <apex:repeat value="{!accItem.Contacts}" var="con">                
  49.                     <tr width="100%" style="text-align: center;">
  50.                         <td style="text-align:left;"><apex:outputText value="{!con.Name}"/></td>
  51.                         <td style="text-align:left;"><apex:outputText value="{!con.FirstName}"/></td>
  52.                         <td style="text-align:left;"><apex:outputText value="{!con.LastName}"/></td>
  53.                         <td style="text-align:left;"><apex:outputText value="{!con.Email}"/></td>
  54.                         <td style="text-align:left;"><apex:outputText value="{!con.Phone}"/></td>
  55.                         <td style="text-align:left;"><apex:outputText value="{!con.Title}"/></td>
  56.                     </tr>                
  57.                 </apex:repeat> 
  58.             </apex:repeat>  
  59.  
  60.         </table>   
  61.     </body>        
  62. </apex:page>

 

Create Apex Class Controller Extension of Visualforce

Step 2:- Create Apex Class : SalesAccountOrderForm_Controller.apxc

 
✪ The Big Announcement: -
As per student's demands, I re-opened my eBook of "Salesforce Tutorial" Limited-time huge discount offer Absolutely 50% Off.
I am thinking to give you discount offer occasion of Gandhi Jayanti for a powerful "Salesforce admin course" where you can Understand from Basic Concepts to advanced label in Salesforce.
👉 So Don't MISS it... (Access Right Now)
👉 Get Huge Discount Offer 50%: - Get eBook
 

From Developer Console >> File >> New >> Apex Class

SalesAccountOrderForm_Controller.apxc [Apex Class Controller]

  1.    public class SalesAccountOrderForm_Controller {
  2.  
  3.     public String MstrId{GET;SET;}
  4.     public Account accObj{GET;SET;}
  5.  
  6.     public SalesAccountOrderForm_Controller(ApexPages.StandardController Controller){
  7.        MstrId = ApexPages.currentPage().getParameters().get('id'); 
  8.  
  9.         accObj = [SELECT Id, Name, Phone, Industry, Rating, Description, Website, TYPE, (SELECT Id, Name, FirstName, LastName, Email, AccountId, Phone, Title FROM Contacts) FROM Account WHERE Id =: MstrId ];
  10.  
  11.     }
  12.  
  13. }

 

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

How do I find the record id of a VF page?

currentPage(). getParameters(). get('id'); The above line will get id URL parameter from browser URL and set into your declared variable 'RecordId'.

How can I get Object name from record ID?

Execute the following snippet of code in the Developer Console to find the Object name based on the Record ID prefix: String objectName = SchemaGlobalDescribe. findObjectNameFromRecordIdPrefix('500'); System. debug(objectName);

How do you pass ID from Visualforce pages to the apex class?

In vf page, add the id as paramater in URL and retrieve in method1 in apex using ApexPages. currentPage(). getParameters(). get('id'), where id is parameter name.

Related Topics | You May Also Like

 
   
 
 

Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment