Skip to main content Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.
Subbu M asked in #Apex
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.');

}

  
4 answers
  1. Oct 10, 2015, 6:56 PM
    Thanks alot All........

     
Loading
0/9000