We can query data using SOQL and display on a Visualforce page.
Let’s display Account and related Opportunities by passing id of an account in the URL. We will query all Opportunities related to the Account using SOQL in Apex, and display data on Visualforce page using PageBlockTable.
Create a Visualforce page using following code:
Visualforce Page:
Name: {!Account.Name}
Apex Code:
Public Class AccountWithOpportunities{ Public List oppList {get; set;} Public AccountWithOpportunities(ApexPages.StandardController ctrl){ oppList = [Select Id,Name,StageName,CloseDate From Opportunity Where AccountId =: ctrl.getId() ]; } }
Let’s test the page using following URL:
https://instance_name.salesforce.com/apex/page_name?id=AccountId
Where instance_name is your domain name or server name, AccountId is the Id of Account for which Opportunities are displayed.
Author:
![]() |
AJOMON JOSEPH Senior Salesforce Architect ![]() ![]() ![]() ![]() |