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 6

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.');
}
   
Best Answer chosen by Subbu
Abhishek BansalAbhishek Bansal
Hi Subbu,

Please change your code with belwo code :
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.');
}

Let me know if you have any issue.

Thanks,
Abhishek

All Answers

Abhishek BansalAbhishek Bansal
Hi Subbu,

Please change your code with belwo code :
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.');
}

Let me know if you have any issue.

Thanks,
Abhishek
This was selected as the best answer
SubbuSubbu
Thanks alot Abhishek
 
SubbuSubbu
HI Abhilash,
I am getting same Compilation Error ... unexpected token: '='   After removing the Quotes