Friday 7 September 2012

Add an Extension to a Visualforce Page


Tutorial #8: Inputting Data with Forms shows how to create a very simple form. In this lesson you will duplicate that page, adding the extension functionality:
  1. Create a new Visualforce page called MyAccountWithExtension.
  2. Use the following as the body of the page:
    <apex:page standardController="Account" extensions="MyExtension"> 
        <p>{!title}</p>
        <apex:form>
            <apex:inputField value="{!account.name}"/>
            <apex:commandButton action="{!save}" value="Save!"/>
        </apex:form>
    </apex:page>
  3. Now access your page with a valid Account identifier passed in as a parameter. Your URL will look something like:https://na6.visual.force.com/apex/MyAccountWithExtension?id=0018000000MDfn1
What you’ll find is that your form pre-populates the input field with the name of the identified account. Great! And it also shows your fancy title with the account name and identifier.
Sample Extension to Rename an Account
When you save the page, you’ll notice that a new line appears above the form. Here’s what’s happening in your page:
  • The attribute extensions="MyExtension" ensures that Visualforce instantiates a copy of your Apex class MyExtension, passing in a reference to the current controller (you’re using the standard controller for Account).
  • The syntax {! title} instructs Visualforce to look for a method called getTitle() and insert the result of calling that method. Because there is such a method in your extension, Visualforce executes it and replaces the statement with the result.

9 comments:

  1. Interesting to learn Salesforce

    ReplyDelete
  2. Nice. Thanks for Salesforce Online Training a good blog SalesForce Online course Hyderabad

    ReplyDelete
  3. Nice post. very useful and informative.keep sharing
    Salesforce training

    ReplyDelete
  4. Nice post. very useful and informative keep sharing
    Salesforce training

    ReplyDelete
  5. I was looking for this script that for sharing. If you are looking for Best Salesforce Training Institute in Noida then CIIT Noida should be your first priority.

    ReplyDelete
  6. Prefer to study this kind of material. Nicely written information in this post, the quality of content is fine and the conclusion is lovely. Things are very open and intensely clear explanation of issue.

    Saleforce Training in Gurgaon
    Saleforce Developer Training in Gurgaon

    ReplyDelete
  7. Thank you for sharing such a nice and interesting blog with us. I have seen that all will say the same thing repeatedly. But in your blog, I had a chance to get some useful and unique information.

    Saleforce Training in Gurgaon
    Saleforce Developer Training in Gurgaon
    Salesforce lightning training in Gurgaon
    Salesforce Einstein training in Gurgaon
    Salesforce integration training in Gurgaon

    ReplyDelete
  8. AlmaMate offers the best Salesforce training in Noida. It is actually regarded as one of the best training institutes in

    Noida for Salesforce. We offer best-in-class SFDC development training not only in Noida but in pan India location. The

    Salesforce training provided by us is devised to make you ready to deploy.

    Our Salesforce training is aligned with the industry standards and it has been designed in keeping in view all the

    necessary inclusions. AlmaMate ensures 100% placement assistance after successful completion of your training. If you are

    looking forward to making your career in the Information Technology domain then join the best Salesforce training in

    Noida.To get further details of our services simply decision India at: (Toll Free) US: +91 9315269123
    Best Salesforce Training in Noida
    Best Salesforce Training in Delhi
    Salesforce Training in Noida

    ReplyDelete