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
rao venkyrao venky 

Custom Controller

While run a following code i have got error like 
[Error] Error: Mycontroller Compile Error: Illegal assignment from List<Account> to Account at line 6 column 3
Can anybody give a solution ?
CODE:
<apex:page controller="Mycontroller" tabStyle="Account">
<apex:form >
<apex:pageBlock title="Account Details">
<apex:pageBlockSection title="Account information">
    <apex:inputField value="{!Account.Name}"/>
    <apex:inputField value="{!account.Phone}"/>
    <apex:inputField value="{!account.Industry}"/>
    <apex:inputField value="{!account.Website}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Account Details">
    <apex:inputField value="{!Account.Fax}"/>
    <apex:inputField value="{!Account.Shippingcity}"/>
    <apex:inputField value="{!Account.AnnualRevenue}"/>     
</apex:pageBlockSection>
<apex:pageBlockButtons>
 <apex:commandButton action="{!Save}" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
CLASS:
public with sharing class Mycontroller
{
 Public Account acc;
 Public Mycontroller()
 {
  acc=[SELECT id,Name,Phone,Industry,Website,Fax,Shippingcity,AnnualRevenue from account Where id=:ApexPages.currentpage().getparameters().get('id')];
  }
 Public account getaccount()
 {
  return acc;
  }
 Public Pagereference Save()
 {
 update acc;
 pagereference page=new Apexpages.StandardController(acc).view();
  return Page; 
 }
}
Best Answer chosen by rao venky
ClintLeeClintLee
Add a LIMIT statement to you query.  

Like this:
 
acc = [SELECT id,Name,Phone,Industry,Website,Fax,Shippingcity,AnnualRevenue from account Where id=:ApexPages.currentpage().getparameters().get('id') LIMIT 1];

Hope that helps,

Clint

All Answers

ClintLeeClintLee
Add a LIMIT statement to you query.  

Like this:
 
acc = [SELECT id,Name,Phone,Industry,Website,Fax,Shippingcity,AnnualRevenue from account Where id=:ApexPages.currentpage().getparameters().get('id') LIMIT 1];

Hope that helps,

Clint
This was selected as the best answer
Gowri Shankar PalanaismayGowri Shankar Palanaismay
Hi rao,

The code you have provided is working fine.. i did'nt get any errors. 
Gowri Shankar PalanaismayGowri Shankar Palanaismay
while invoking the VF page add /?id=Account_Id after the Page name in the URL