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 

Re: please help me.solve the error

 

Error: classba Compile Error: Illegal assignment from LIST<Account> to LIST<account> at line 11 column 7



 

public with sharing class classba {
public String accName { get; set; }
List<Account> lstaccount = new List<Account>();
List<contact> lstcontacts = new List<contact>();
set<string> accIds = new set<string>();
public List<contact> getConRecords() {
lstcontacts.clear();
accIds.clear();
lstaccount.clear();
system.debug('****AccNameTextValue is *****'+accName);
lstaccount=[select id,name,phone from Account where name=:accName];
for(Integer i=0;i<lstaccount.size();i++)
{
accIds.add(lstaccount[i].Id);
}
lstcontacts =[select id,name,phone from contact where accountid in : accIds];
system.debug('**** List of Contacts for Test is ***'+lstcontacts);
return lstcontacts;
}
public pagereference showContacts() {
return null;

}
}

 

<apex:page controller="classba" sidebar="false">
<apex:form >
<apex:inputText value="{!accName}"/>
<apex:commandButton value="search" action="{!showcontacts}"/>
<apex:actionstatus id="mystatus" starttext="please wait it is loading contacts.......">
<apex:facet name="stop">
<apex:outputpanel id="out">
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!conRecords}" var="c">
<apex:column headerValue="Contacts">
{!c.Name}
</apex:column>
<apex:column headerValue="Phone" value="{!c.phone}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputpanel>
</apex:facet>
</apex:actionstatus>
</apex:form>
</apex:page>

kiranmutturukiranmutturu

i hope nothing wrong in your code

sf sharathsf sharath

but y i'm getting that error

kiranmutturukiranmutturu

try to create the same copy of the class and page with different names and try once...

sf sharathsf sharath

[select id,name,phone from Account where name=:accName];

 

 

 

in that what is id here?

kiranmutturukiranmutturu

salesforce generated Id for every record in the database automatically and it is unique through out the system

bob_buzzardbob_buzzard

Do you have a local class named account?  I've hit  this error before and that was the problem. 

sf sharathsf sharath

ya i,ve it account class

bob_buzzardbob_buzzard

So the compiler here thinks that the List<Account> on the left hand side of the assignment is your custom account class, and it can't assign a list of sobject accounts to that.

 

The fix would be to rename your custom account class to something else.  If it contains an account and adds functionality, something like AccountWrapper.  It improves readability and maintainability too.

 

 

kiranmutturukiranmutturu

i think as your logic requires id only then u can make use of sobject try this before changing that account class name to some thing

 

public with sharing class classba {
public String accName { get; set; }
List<sobject> lstaccount = new List<sobject>();
List<contact> lstcontacts = new List<contact>();
set<string> accIds = new set<string>();
public List<contact> getConRecords() {
lstcontacts.clear();
accIds.clear();
lstaccount.clear();
system.debug('****AccNameTextValue is *****'+accName);
lstaccount=[select id,name,phone from Account where name=:accName];
for(Integer i=0;i<lstaccount.size();i++)
{
accIds.add(lstaccount[i].Id);
}
lstcontacts =[select id,name,phone from contact where accountid in : accIds];
system.debug('**** List of Contacts for Test is ***'+lstcontacts);
return lstcontacts;
}
public pagereference showContacts() {
return null;

}
}

bob_buzzardbob_buzzard

I'd still recommend you change the name of the class - using generic sobjects in place of typed instances and having custom classes named the same as sobjects is storing up maintainability problems down the road - it makes it much more difficult for someone coming in cold to understand what you have done.  

kiranmutturukiranmutturu

yes @bob its absouletly true but what i am thinking is  if there is alot of depencies in their classes its difficult na thats why i thought of this...but as per the practice its better to avoid naming w.r.t  native paltform words... thank you Folk....