You need to sign in to do that
Don't have an account?
Trick
Vusual force problem explanation
Hi Friends ,
Can somebody please explain lines in red.I need to understand the functionality.For example,what kind of value will value="{!account.contacts}" have. Is it retrieving account or contact information etc.
<apex:page standardController="account">
<apex:pageblock title="Hello {!$user.firstname}">
You are displaying contact from the {!account.name}account.
click contact's name to view his or her details.
</apex:pageblock>
<apex:pageblock title="contacts">
<apex:form>
<apex:datatable value="{!account.contacts}" var="contact" cellpadding="4" border="1">
<apex:column>
<apex:commandlink rerender="detail">
{!contact.name}
<apex:param name="cid" value="{!contact.id}"/>
</apex:commandlink>
</apex:column>
</apex:datatable>
</apex:form>
</apex:pageblock>
<apex:outputpanel id="detail">
<apex:detail subject="{!$currentpage.parameters.cid}" relatedlist="false" title="false"/>
</apex:outputpanel>
</apex:page>
Thanks,
Trick
First, I would suggest reading the Force.com Developer Guide. This is almost identical to the example in Chapter 9, Section "Developing Visualforce Pages" around Page 250 or so. They explain this crystal clear, and I doubt I can explain it better, but I'll add my thoughts anyway.
This VF Page is using the standard Account Controller. So when a user accesses this page the VisualForce already has access to the Account Record. So if we go through your lines:
<apex:datatable value="{!account.contacts}" var="contact" cellpadding="4" border="1">
-This line is createing a data table and iterating over all the contacts for your account. Each individual contact is called 'Contact' per the var attribute. It will iterate over every contact in the account.contacts array and generate HTML for each one.
{!contact.name}
-- These two lines are displaying the current Contacts name and creating a parameter for each Contact ID, which can be used to find a specific contact
All Answers
First, I would suggest reading the Force.com Developer Guide. This is almost identical to the example in Chapter 9, Section "Developing Visualforce Pages" around Page 250 or so. They explain this crystal clear, and I doubt I can explain it better, but I'll add my thoughts anyway.
This VF Page is using the standard Account Controller. So when a user accesses this page the VisualForce already has access to the Account Record. So if we go through your lines:
<apex:datatable value="{!account.contacts}" var="contact" cellpadding="4" border="1">
-This line is createing a data table and iterating over all the contacts for your account. Each individual contact is called 'Contact' per the var attribute. It will iterate over every contact in the account.contacts array and generate HTML for each one.
{!contact.name}
-- These two lines are displaying the current Contacts name and creating a parameter for each Contact ID, which can be used to find a specific contact
http://wiki.developerforce.com/index.php/Force_Platform_Developer_Guide
Thanks cory for the explanation .I have been reading and practicing visualforce.So it will take me a while to understand and become good at it.
I have another problem can u help me with that.
1) How will constructor fire in the below given code.Here, we are only accessing the code through visual force.We are not creating any object so how will constructor get fired.
2) The code has used upsert function.If I am not mistaken upsert can be used to either insert or update a record.I don't think that we can insert new record because we have associated existing account record with the code .Hence,every time I access a record I see a value in it which means I can only update and not insert.
I know I am missing something,Can u please help me with that.
Do u have some knowledge about the below given line:-? if possible please explain.
return (new ApexPages.StandardController(account)).view();
Thanks,
Trick
1. A Constructor for a Controller or Extension will get fired with the Visualforce Page is requested by the browser prior to rendering the page. Salesforce nows which constructors to invoke because you specify them in the attributes of the visualforce apex:page tag (controller, extension). The contructor will execute first, then the page will render with values from the controller as appropriate.
2. It looks like this code will do either an insert or a update based on if they pass a paramter named id in the URL. Soemthing like this will perform Upsert: na7.salesforce.com/apex/NewAndExistingPage?id=001ABCDEFGHKIJK. Something like this na7.salesforce.com/apex/NewAndExistingPage would perform an insert based on how your constructor is handling the input.
3. return (new ApexPages.StandardController(account)).view(); statement will naviage the user to the Standard Salesforce View Page for this account. Documentation on this is provided in the Force.com Visualforce Guide.