title: Salesforce Apex - Populating an object from SOQL query
body: <p>I have a simple SOQL query that returns information relating to a Contact and CampaignMember. I'm attempting to populate a custom object with the results of the SOQL query. However I get the following error when loading the Visualforce page:</p>
  
  <p><strong>Invalid field campaign.name for CampaignMember</strong></p>
  
  <pre>List campaignMembers = [select campaign.name, contact.id,contact.firstname, contact.lastname, status, campaignId from CampaignMember where contactId = '003U000000U0eNq' and  campaignId in :campaigns];
  
  for (Integer i = 0; i &lt; campaignMembers.size(); i++) {
      results.add(new CampaignMemberResult(
          (String)campaignMembers[i].get('CampaignId'), 
          (String)campaignMembers[i].get('campaign.name'),
          true
      ));
  }
  </pre>
  
  <p>I've ran the SOQL query seperately in the Developer Console and it queries successfully. Why can I not pull in the campaign.name from the SOQL query within the for loop?</p>