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
hmoh1920hmoh1920 

Access of the query results

Hi,

 

I have this code :

 

global void execute(SchedulableContext ctx)
{

public List<String> account_email{get;set;}
public Map<string,string> Map_usr{get;set;}

Map_usr=new Map<string,string>();

 

account =[Select (Select Etape_de_cr_ation__c From Opportunities where Etape_de_cr_ation__c='Etape2'),
 (Select Id, Email, Destinataire__c From Contacts where Destinataire__c='Oui') From Account a];

 


        for(Account c:account)
        {

            system.debug('____id__'+c.id+'____Email_____'+c.Email+'___DATE_______'+c.Destinataire__c);

//error at this line :Save error: Invalid field Email for SObject Account


            Map_usr.put(c.id,c.Email);

            if(c.Email!=null)

                account_email.add(c.Email);

        }

       if(account_email.size()>0)

           sendmail(account_email);

}

 

my question is: how to recover the data (email) of the query?

 

thanks for your help!

 

 

cordially

moh.

 

 

 

Navatar_DbSupNavatar_DbSup

Hi,

You have to use the inner loop for access the email and Destinataire__c field. Because these fields are exist in child object not in account object.

 

Try the below code snippet as reference:

 

for(Account c:account)

{

 

                for(Contact dd:c.contacts)

                {

                                system.debug('____id__'+c.id+'____Email_____'+dd.Email+'___DATE_______'+dd.Destinataire__c);

                }

               

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

hmoh1920hmoh1920

i tested your code and i have this error   :Save error: Invalid field Email for SObject Account


you have another suggestion?

 

 

thanks

 

cordially

moh.

KapilCKapilC

HI Moh,

 

Please try this code...

 

global void execute(SchedulableContext ctx)
{

public List<String> account_email{get;set;}
public Map<string,string> Map_usr{get;set;}

Map_usr=new Map<string,string>();

 

account =[Select (Select Etape_de_cr_ation__c From Opportunities where Etape_de_cr_ation__c='Etape2'),
 (Select Id, Email, Destinataire__c From Contacts where Destinataire__c='Oui') From Account a];

 


        for(Account a:account)
        {

            for(Contact c : contacts)
			{
				system.debug('____id__'+c.id+'____Email_____'+c.Email+'___DATE_______'+c.Destinataire__c);

				Map_usr.put(c.id,c.Email);

				if(c.Email!=null)
					account_email.add(c.Email);
			}
        }

       if(account_email.size()>0)

           sendmail(account_email);

}

 

[If you got answer from my post please mark it as solution.]
Thanks,
Kapil