title: How do you parse a SOQL AggregateResult column with no value?
body: <p>Let's say you run a <a href="http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql.htm" rel="nofollow">SOQL</a> aggregate query that looks like this:</p>
  
  <pre><code>select OwnerId, sum(ExpectedRevenue)val from Opportunity GROUP BY ROLLUP(OwnerId)
  </code></pre>
  
  <p>For whatever reason, there are no Opportunities with ExpectedRevenue fields populated. </p>
  
  <p>You get a table that looks like this:</p>
  
  <blockquote>
    <blockquote>
      <p>val___|OwnerId</p>
  
  <pre><code>     |Id1
       |Id2
       |Id3
  </code></pre>
      
      <p>4/4 records.</p>
    </blockquote>
  </blockquote>
  
  <p>(sidenote: how do you put in tabular data without it looking terrible?)</p>
  
  <p>Take note that the "val" columns are all null and the last OwnerId column is also null.</p>
  
  <p>There are 4 rows because SOQL returns a "total" row as well on rollups.</p>
  
  <p>While looping through the AggregateResult[] that gets returned the code blows up on a line that looks like this: AggregateResult[0].get('val'); with a "System.NullPointerException: Attempt to de-reference a null object"</p>
  
  <p>However, if just 1 of those users has some data, then the whole thing works. So I'm guessing that if no rows have any data in a particular column, that column does not exist at all and calls to retrieve it blow up.</p>
  
  <p>So my question is how do you determine if a column exists to avoid the null reference error?</p>