i have already done some codes check the codes below and tel me what's wrong in this

public PageReference send()
  List<Contact> accounts=[SELECT Email,id FROM Contact WHERE AccountId ='001i000000g7erl'];
  List<Id> emailid=new list<Id>();  
  for(Contact mail: accounts)

     List<Brand__c> notes = [SELECT Name__c,(SELECT CreatedBy.Name,Title,Body FROM Notes)FROM Brand__c Where Id='a0di0000003EkAU'];
     List<String> note=new list<String>();
     for(Brand__C no:notes)

    //String[]address=new String[] {'note'};  
    Messaging.MassEmailMessage emails = new Messaging.MassEmailMessage();
    Messaging.sendEmail(new Messaging.MassEmailMessage[] {emails});
    return null;

my custom object name is brand and i want o fetch the notes and attachment of tat object in this code i have fetch the contact email and i want to fetch the notes and attachment title and body if in this code im getting error like this

Initial term of field expression must be a concrete SObject: LIST at line 31 column 20 if any one know this pls help me in this

  • Which line in this method refers to line 31? There's less than 30 lines provided.
    – jonnybro
    Mar 26, 2014 at 7:02
  • eamils.setBody(notes.Body) this is the line im getting error
    – user7538
    Mar 26, 2014 at 7:54

2 Answers 2


Your variable notes is a list of Body__c objects (containing one item only). Each entry in that list also has a list of Node objects in a variable called Notes. (See e.g. Relationship Queries.)

So to loop over the zero or more notes you need something like this:

Messaging.MassEmailMessage[] emails = new Messaging.MassEmailMessage[] {};
for (Note n : notes[0].Notes) {
    Messaging.MassEmailMessage email = new Messaging.MassEmailMessage();

You should probably rename your variables to make the code clearer.


As it doesn't look like and values from Brand__c are used, the simpler solution is to just query the Note object directly like this:

Id brandId = 'a0di0000003EkAU';
for (Note n : [
        select CreatedBy.Name,Title,Body
        from Note
        where ParentId = :brandId
        ]) {

A similar query can be done for Attachment too.

  • it doesnt work is showing error like variable doesnt exist
    – user7538
    Mar 26, 2014 at 9:28
  • 2
    @user7538 You are best placed to figure out errors like that as you will also have been given a line number and you have the full current source code.
    – Keith C
    Mar 26, 2014 at 9:58

Your naming of variables makes this code very confusing.

email.setBody(notes.Body) notes is a List<Brand__c> so it won't have a Body field. You'll want to do notes[0] to get the Brand__c sObject, even then you're getting a list of Note objects as part of your Brand__C sObject so you'll need to either

  1. Get the Body of the first Note notes[0].Notes[0].Body <-- this assumes at least 1 Note was returned.
  2. Loop through all the Notes that were returned and collect all the body information


String bodies = '';
for(Note n : notes[0].Notes){
    n.Body + ' \n ';

Also, you are only getting the Notes child object, your code does not get the Attachment child object.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .