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
Lohith MatamLohith Matam 

Simple VF

Hi everyone i am new to salesforce i had some requirement please tell me 

Create a page which displays a subset of Opportunity fields using apex:outputField components. Bind the Name, Amount, Close Date and Account Name fields to the apex:outputField components.The page must be named 'OppView'.
It must reference the Opportunity standard controller.
It must have an apex:outputField component bound to the Opportunity Name.
It must have an apex:outputField component bound to the Opportunity Amount.
It must have an apex:outputField component bound to the Opportunity Close Date.
It must have an apex:outputField component bound to the Account Name of the Opportunity.

My Answer:
<apex:page standardcontroller="Opportunity">
<apex:pageBlock>
   <apex:pageBlockTable >
      <apex:outputField value="{!Opportunity.Opportunity Name}"/>
      <apex:outputField value="{!Opportunity.Amount}"/>
      <apex:outputField value="{!Opportunity.Close Date}"/>
      <apex:outputField value="{!Opportunity.Account Name}"/>
   </apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

Error Displaying:
Error: Missing required attribute value in <apex:pageBlockTable> in OppView at line 3 column 25

Please help to improve my knowledge
 
Best Answer chosen by Lohith Matam
praveen murugesanpraveen murugesan
Hi Lohith,

If you want to use pageBlockTable you need to assign a value for that. Eg:
<apex:pageBlockTable value="{!recordTodisplay}" var="r" id="table_Expense">

and for recordtodisplay you need to pass value from controller

and you can display like

<apex:pageBlockTable value="{!recordTodisplay}" var="r" id="table_Expense">

<apex:column headervalue="ID">
<apex:outputField value="/{!r.d}" />	
</apex:column>

</apex:pageBlockTable >
For your requirement you need to do like this
 
<apex:page standardcontroller="Opportunity">
<apex:pageBlock>
  
      <apex:outputField value="{!Opportunity.Name}"/>
      <apex:outputField value="{!Opportunity.Amount}"/>
      <apex:outputField value="{!Opportunity.CloseDate}"/>
      <apex:outputField value="{!Opportunity.Account.Name}"/>
  
</apex:pageBlock>
</apex:page>

Thanks
-- Praveen Murugesan

Mark this solution if its helps.

All Answers

surasura
<apex:page standardcontroller="Opportunity">
<apex:pageBlock>
   <apex:pageBlocksection title="Opportunity Details" >
      <apex:outputField value="{!Opportunity.Opportunity Name}"/>
      <apex:outputField value="{!Opportunity.Amount}"/>
      <apex:outputField value="{!Opportunity.Close Date}"/>
      <apex:outputField value="{!Opportunity.Account Name}"/>
   </apex:pageBlocksection >
</apex:pageBlock>
</apex:page>

replace <apex:pageblocktable> tag with <<apex:pageBlocksection>
sandeep sankhlasandeep sankhla
HI Lohit,

In this case there is no use of pageblocktable because you are only showing the opportunity details..if you are iterating over a list then we should use pagebloktable ....in this case you will always have only 1 record so its not required...you can use what Sura has mentioned above..

But you are getting error because you have not provided mandatory field..which is Value and Var in pageblockTable...

Please check below link for more details how to use
https://www.salesforce.com/docs/developer/pages/Content/pages_compref_pageBlockTable.htm

Thanks,
Sandeep
Mudasir WaniMudasir Wani
Hi Lohith,
Use the below code
 
<apex:page standardController="Opportunity">

    <apex:pageBlock title="Opportunity Fields">

        <apex:pageBlockTable value="{!Opportunity}" var="oppor">

            <apex:outputField value="{!oppor.Name}"/> 
			<apex:column value="{!oppor.Amount}"/> 
			<apex:column value="{!oppor.CloseDate}"/> 
			<apex:column value="{!oppor.AccountId}"/> 
			<apex:column value="{!oppor.AccountId.Name}"/> 

        </apex:pageBlockTable> 

    </apex:pageBlock> 

</apex:page>
Then your URL should have an opportunityId.

Example - https://salesforceInstanceName/opportunityId
in my case it is --https://eu5.salesforce.com/006240000039pAI

Don't forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.
 
kumar tanwarkumar tanwar
Hello Lohith Matam,
If you use PageBockTable then you must bind with ListOf Record..Depend on your requirment how many records showing on your page. If you show only single record in page then you remove PageBockTable.

Thanks..
Lohith MatamLohith Matam
should i write a controller class for the above code??? because i am not getting what i want please help....
Lohith MatamLohith Matam
should i write a controller class for the above code??? because i am not getting what i want please help....
praveen murugesanpraveen murugesan
Hi Lohith,

If you want to use pageBlockTable you need to assign a value for that. Eg:
<apex:pageBlockTable value="{!recordTodisplay}" var="r" id="table_Expense">

and for recordtodisplay you need to pass value from controller

and you can display like

<apex:pageBlockTable value="{!recordTodisplay}" var="r" id="table_Expense">

<apex:column headervalue="ID">
<apex:outputField value="/{!r.d}" />	
</apex:column>

</apex:pageBlockTable >
For your requirement you need to do like this
 
<apex:page standardcontroller="Opportunity">
<apex:pageBlock>
  
      <apex:outputField value="{!Opportunity.Name}"/>
      <apex:outputField value="{!Opportunity.Amount}"/>
      <apex:outputField value="{!Opportunity.CloseDate}"/>
      <apex:outputField value="{!Opportunity.Account.Name}"/>
  
</apex:pageBlock>
</apex:page>

Thanks
-- Praveen Murugesan

Mark this solution if its helps.
This was selected as the best answer
Lohith MatamLohith Matam
when i am copying sura answer iam getting error as Error: Could not resolve field 'Opportunity Name' from <apex:outputField> value binding '{!Opportunity.Opportunity Name}' in page OppView
sandeep sankhlasandeep sankhla
Hi Lohith,

It should be .Name 

 
Lohith MatamLohith Matam
Thank u  all  for giving me answers by spending your valuable time for me
sfdcvirajsfdcviraj
How will I get to know when to use .Name and when not to use it?

Example -

"{!Opportunity.Account.Name}" - Here I am using the Account.Name and it works.
"{!Opportunity.CloseDate}" - Here I am not using the dot between Close Date. And throws error if used dot.

Bit confusing, please make me understand.
Thank you.
SAHG-SFDCSAHG-SFDC
Hi,

I wrote this and Seems right

<apex:page standardController="Opportunity">
<apex:pageblock >
    <apex:pageBlockSection >
                <apex:outputField value="{! Opportunity.Name }"/>
                <apex:outputField value="{! Opportunity.Amount }"/>
                <apex:outputField value="{! Opportunity.CloseDate }"/>
                <apex:outputField value="{! Opportunity.Account.Name }"/>

    </apex:pageBlockSection>
  
</apex:pageblock>
</apex:page>
pradeep jsohipradeep jsohi
hi praveen murugesan;
i paste same code in my vf page but output is blank?
please suggest me where i m wrong?
srjpd2srjpd2
Hi Pradeep,

You are not able to see any values because there is no account instance is linked to the view.

To view details, you must append &id=someid at the end of URL.

Hope this resolves your concern.

Thank you.