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
SubbuSubbu 

unexpected token: '=' at line 5 Plese help me ................

string ratingValue = 'Hot';
public List<Account> lstAccount{get;set;}
string strQuery = 'select id, name, rating, industry,( select id, firstname, lastname, phone, fax from contacts) from account where rating =: ratingValue';
lstAccount = Database.Query(strQuery);
    if(lstAccount.size()!= 0)
    {
    for(Account acc : lstAccount)
    {
        system.debug(acc.id + ' ----> '+ acc.name + ' ----> '+acc.rating + ' ----> '+ acc.industry );
        
        system.debug('Contact Records Information.');
        system.debug('Contact Count ....: '+ acc.contacts.size());
        
        if(acc.contacts.size() > 0)
        {
            for(contact con : acc.contacts)
            {
                system.debug(con.id + ' ---> ' + con.firstname + ' ----> ' + con.lastname);
            }
        }
        else
            system.debug ('No Contacts for this Account');
    }
}
else
{
    system.debug('Account Record Not Found.');
}
  
Alexander TsitsuraAlexander Tsitsura
Hi, 

As i understund 
public List<Account> lstAccount{get;set;}

should be a local variable

try 
List<Account> lstAccount[] = new List<Account>();

Thanks,
Alex
JAY_PJAY_P
Change the value of  public List<Account> lstAccount{get;set;} to List<Account> lstAccount[] = new List<Account>();
Thank You 
Jithin Krishnan 2Jithin Krishnan 2
Hi Subbu,
You can't have statements like that directly inside a class. Please keep only field declarations inside class and all the other statements inside a method in class. Also the field intitalisations should be inside a constructor. Something like this:
public class Test1 {
    public List<Account> lstAccount{get;set;}
    String ratingValue;
    public Test1(){
        ratingValue='hot';
    }
    public void methodname(){
    lstAccount.addAll([select id, name, rating, industry,( select id, firstname, lastname, phone, fax from contacts) from account where rating =:ratingValue]);
    if(lstAccount.size()!= 0)
    {
    for(Account acc : lstAccount)
    {
        system.debug(acc.id + ' ----> '+ acc.name + ' ----> '+acc.rating + ' ----> '+ acc.industry );
        
        system.debug('Contact Records Information.');
        system.debug('Contact Count ....: '+ acc.contacts.size());
        
        if(acc.contacts.size() > 0)
        {
            for(contact con : acc.contacts)
            {
                system.debug(con.id + ' ---> ' + con.firstname + ' ----> ' + con.lastname);
            }
        }
        else
            system.debug ('No Contacts for this Account');
    }
}
else
{
    system.debug('Account Record Not Found.');
}
    }
}


Note: I have removed the syntactical errors. Please change it according to your need.
Thanks
JK
SubbuSubbu
Thanks alot All........