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
sf sharathsf sharath 

please help me.

Error: input Compile Error: Illegal assignment from LIST<Account> to account at line 8 column 3. please tell me the error meaning

 

 

 

 

 

 

public class input {
public account a{get;set;}
public input()
{
id id1 = ApexPages.currentpage().getParameters().get('id');
if(id1<>null)
{
a= [select id,name,industry,phone from account where id = :id1];
}
else
{
a = new account();
}
}

public PageReference save() {
upsert a;
a= new account();
return (new ApexPages.StandardController(a).view());
}

}

 

 

 

 

<apex:page controller="input">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!a.name}"/>
<apex:inputField value="{!a.phone}"/>
<apex:inputField value="{!a.industry}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

bob_buzzardbob_buzzard

In this line:

 

a= [select id,name,industry,phone from account where id = :id1];

 

you are assigning the list that is returned from the SOQL call to a single account.  Something like the following should fix it (and protect you against an id that doesn't exist!)

 

List<Account> accs=[select id,name,industry,phone from account where id = :id1];
if (accs.size()>0)
{
   a=accs[0];
}

 

 

sf sharathsf sharath
thank you so much
sf sharathsf sharath

<p>Error: input Compile Error: Illegal assignment from LIST to LIST at line 8 column 2</p>

bob_buzzardbob_buzzard

It works for me - can you post the updated code.