Friday 7 September 2012

Create a Page with a Controller - Visualforce


You create controllers the same way you created extensions in the previous tutorial, by navigating to Setup | Develop | Apex Classes | New. You can also have the Visualforceeditor create them for you.
  1. Create a new Visualforce page named AccountWithContacts.
  2. Enter the following as the body of the page:
    <apex:page controller="MyController">
        <apex:form>
            <apex:dataList value="{! myaccounts}" var="acct">
                <apex:outputText value="{! acct.name}"/>
            </apex:dataList>
        </apex:form>
    </apex:page>
    The contents of the page will be very familiar to you. The primary component iterates over a list of accounts, displaying their names. Where is myaccounts defined? It’s not defined yet, but it will reside in the controller that you specified, MyController.
  3. Click Save.
  4. Visualforce notes that the class MyController doesn’t exist. Click Create Apex class 'public class MyController'.
  5. Visualforce notes that there’s an unknown property myaccounts and offers to create it for you. Click Create Apex method 'MyController.getMyAccounts'.
You will notice two things in your Visualforce editor. First, there’s another error message: Unknown property 'String.name'. This happens because you haven’t quite fully defined the getMyAccounts() method yet. Visualforce doesn’t know the type that will be returned by that method. You’ll also notice a new tab has appeared next to Page Editor titled Controller. This lets you modify the controller’s Apex class.

Visualforce development mode Page Editor

11 comments:

  1. then how should I overcome this problem.....

    ReplyDelete
  2. I am following your blog from the beginning, it was so distinct & I had a chance to collect conglomeration of information that helps me a lot to improvise myself.

    ReplyDelete
  3. Cloud is one of the tremendous technology that any company in this world would rely on(Cloud computing course in Chennai). Using this technology many tough tasks can be accomplished easily in no time. Your content are also explaining the same(Cloud computing training chennai). Thanks for sharing this in here. You are running a great blog, keep up this good work.

    ReplyDelete
  4. There are lots of information about latest technology and how to get trained in them, like Big Data Training in Chennai have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get trained in future technologies(Big Data Training). By the way you are running a great blog. Thanks for sharing this.

    Hadoop Training in Chennai | Big Data Training in Chennai

    ReplyDelete


  5. The way you have explained the Big Data concept is really superb! I have never come across such a informative blog in my career. Nowadays, Hadoop course is in high demand by most of the professional to enhance their career.

    Regards:

    Big Data Training |
    Big Data Course in Chennai

    ReplyDelete
  6. Nice blog on Selenium Testing!!! I agree with your points, Testing will help whole organization to handle the projects in efficient manner.

    Selenium Training in chennai |
    selenium training in t nagar 

    ReplyDelete