[SalesForce] Getting an error when trying to create a custom page with a custom controller

I am trying to create a custom Visualforce page with a custom controller by following the example on this page:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_custom.htm

However, when I view the page that uses the code given in the example, I get this error:

List has no rows for assignment to SObject An unexpected error has
occurred. Your development organization has been notified.

I just copied and pasted the code from the example into a custom class and a custom visualforce page. How do I fix this issue? Thanks!

Best Answer

The error your receiving is due to a lack of an Account object in your current development organization.

Check to make sure you have at least 1 Account record that matches the id your supplying to the page via the url parameter that is being input to the page.

Maybe you could have the page output a random account object changing:

 public MyController() {
    account = [SELECT Id, Name, Site FROM Account 
               WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}

to:

 public MyController() {
    account = [SELECT Id, Name, Site FROM Account LIMIT 1];
}
Related Topic