+ Start a Discussion
U JayU Jay 

SendMailingAddressNotificationAcntCntrlr Compile Error: Initial term of field expression must be a concrete SObject

public void sendHouseHoldmailingAddressNotificationAction(){
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();for(String destinationEmailItem : fetchDestination()){
             String emailAddr = destinationEmailItem.Email;
             <<<some code>>>
          }
}
public List<Contact> fetchDestination(){
         List<Contact> destination = new List<Contact>();
         for(Contact contactRecord : [SELECT id, Account.BillingCity, Account.Billingstate, Age_Group__c, npsp__Current_Address__c,AccountID, Account.Invalid_Address__c, Email
                                      FROM Contact
                                      WHERE Account.Invalid_Address__c = True AND Age_Group__c = 'Adult' AND Email != null]){
             destination.add(contactRecord);   
         }
         if(destination.size() > 0){
             return destination;
         }
         else{
             return null;
         }
     }
I got error "SendMailingAddressNotificationAcntCntrlr Compile Error: Initial term of field expression must be a concrete SObject: String at" bold line. Why?
Thanks in advance.
Anoop yadavAnoop yadav
Hi,

What is the return type of this( fetchDestination() ) function.

If it is returning a string then use "String emailAddr = destinationEmailItem;"
instead of "String emailAddr = destinationEmailItem.Email;".
Anoop yadavAnoop yadav
In the below method you are getting the List of Contact.
Then you should use.
for(Contact con : fetchDestination()){
             String emailAddr = con.Email;
             <<<some code>>>
          }
Anoop yadavAnoop yadav
But it will only store the last Email Address.
To get all the Email Address you should use List of string.

for(Contact con : fetchDestination()){
List<String> emailAddrList = new List<String>();           
String emailAddr = con.Email;
emailAddrList.add(emailAddr);
             <<<some code>>>
          }